tags:

views:

72

answers:

4

Hi,

I have got class Car, and each class has list of extras (leather, abs, Folding mirrors etc...)

public Extra
{
public bool Paid {get;set;}
public string Name {get;set;}
public string Code {get;set;}
}

And now, better is:

class Car
{
public Extra Leather {get;set;}
public Extra FoldingMirrors {get;set;}
public Extra Abs {get;set;}
}

or better:

class Car
{
private List<Extra> _listOfExtras=new List<Extra>

public List<Extra> ListOfExtras
{
...
}
}

And the worst part:

My winforms application works offline and one per month is sending datas for me.

I must hold list Of available (foreach car user choose extras) extras in this application so better way I think is option one.

how hold this list of extras in my applications ? It connect with webservice only one time per month.

+1  A: 

A list or dictionary (for easier access) of extras would be more flexible.

It would mean that as extras were added and/or removed from a car you wouldn't have to modify the Car class which you would have to do if each were added explicitly.

There are various ways to store the list locally. You could serialise to a file - either plain text or XML which would be better as you've got classes that do the serialisation for you, or you could hold it in a local database.

ChrisF
Ok, but how hold this list of extras in my applications ? It connect with webservice only one time per month
@phenevo - there are various ways to store the list locally. You could serialise to a file - either plain text or better XML, or you could hold it in a local database.
ChrisF
+2  A: 

Personally (seeing this is subjective), I would use an interface for Extra (eg IExtra). I would also go for the second 'option' of having a list/dictionary of extras contained in the Car class.

If needed, they can be exposed like in option 1, by just looking up the value in the list/dictionary.

leppie
Ok, but how hold this list of extras in my applications ? It connect with webservice only one time per month
+1  A: 

I would store it in a Dictionary<string, Extra>. You don't want the same extras showing up more than once... Or at least paying for them more than once :-)

Also, Extra should be an interface (or at the very least an abstract class)..

As for storage, you could serialize the Car class out to XML.

Adrian Regan