DEV Community

Discussion on: SOLID Principles for OOP

Collapse
 
mdjorov profile image
Miro

Yes, for me something is not right either. The if statement should be in a Factory class, that knows what object to return. Something like:
We have somewhere a class factory
IOrder OrderFactory(int size)
{
if (size < 100)
return new Order;

return new LargeOrder();
}

and a class using it:
class Foo ()
{
void Bar(int size)
{
IOrder order = OrderFactopy(size);
order.MakeOrder();
}
}
This way the Foo class won't change if somewhere in the future an ExtraLargeOrder class appear. The only place that will change is the OrderFactory class, but all other code won't.