Reputation: 20262
I try to model class where situation is similar to:
public class Car
{
private List<Gratis> _gratises=new List<Gratis>();
public List<Gratis> Gratises
{
get { return _gratises; }
set { _gratises= value; }
}
public class Gratis
{
public string Name {get;set;}
public int ID {get;set;}
}
In one place user manages list of gratises. He can Add, Remove, or Edit gratises.
In second module user can manages cars:
He can add or remove gratis to car.
Is my model ok ?
If is, how implement this?
I have datagridview and:
get list of gratis from database, and next get a list of gratis of car ?
Or maybe add IsChecked field ?
Sql Server 2005. asmx, and WinForms
Upvotes: 0
Views: 67
Reputation: 7361
Look at M.Fowler refactoring approach Encapsulate Collection
Also note that in get properties return read-only collection:
public List<Gratis> Gratises
{ get { return _gratises.AsReadOnly(); } }
Upvotes: 2
Reputation: 9072
It looks pretty good, 2 considerations:
Why is _gratises
public? it is
accessible through Gratises
, it
should probably be private
Do you mind if someone replaces the
"gratises" list in its entirety? If
you do, I would remove the setter
and add AddGratis(Gratis)
and
RemoveGratis(Gratis)
methods that proxy to
the underlying List.
Upvotes: 1