views:

69

answers:

1

I have an abstract base class called Person with subclasses Employee and Customer.

How do you deal with the situation where Employee is also a Customer? How would this series of entities be created?

Cheers

+8  A: 

If you want Employee to be a Customer, then Customer probably should not derive from person, but be it's own hierarchy of classes, which (typically) encapsulates a Person.

In many ways this makes more sense, since a Customer may also be a company or other form of entity, and not a Person.

Reed Copsey
+1 many times people think OO too literally. Hanselminutes once had an interesting discussion about this, though I forget who Scott was talking to. Basically the question is is a Square a Shape? Physically, yes. However, if you change the Length you implicitly change the Width, so this could cause issuesin the OO world where calling code doesn't expect this. Point is, sometimes OO is not 1:1 with the way we see the world around us.
statichippo