1

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.

user278618
  • 19,306
  • 42
  • 126
  • 196
  • Can you fix some spelling issues and describe you last requirement about saving with more details? – Restuta Jun 21 '10 at 11:20

3 Answers3

2

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
  • 115,091
  • 17
  • 196
  • 297
  • Ok, but how hold this list of extras in my applications ? It connect with webservice only one time per month – user278618 Jun 21 '10 at 11:23
1

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
  • 134,786
  • 31
  • 255
  • 325
  • Ok, but how hold this list of extras in my applications ? It connect with webservice only one time per month – user278618 Jun 21 '10 at 11:24
  • 1
    @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 Jun 21 '10 at 11:41
1

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
  • 2,240
  • 13
  • 11