views:

65

answers:

2

Hi,

I get answer in:

http://stackoverflow.com/questions/3084125/object-modelling-problem

that I should use interface instead class Extra in this case:

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

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

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

I don't understand why it is better solution

A: 

The decorator pattern should address this problem very well.

http://stackoverflow.com/questions/2707401/please-help-me-understand-the-decorator-pattern-with-real-world-example/2707425#2707425

this. __curious_geek
Why do you think that the decorator pattern has anything to do with this?
Stefan Steinegger
Car is a basic object which might carry one or more Extras. So Car object can be decorated by Extras.
this. __curious_geek
But the Extras do not act as Cars. The decorator acts as the decorated object, eg. a scrollable window acts as a window (or the ToppingsDecorator acts as a pizza in the linked example).
Stefan Steinegger
+1  A: 

It really depends of the specific requirements and technical constraints. You can't expect any good advise here, because we all can just guess what you are doing with this classes.

For instance. As long as the Extra class consists of only these three values, I don't know why it should be an interface. It could be designed as a value object.

Stefan Steinegger