Originally Posted by
Bryan
Ok, lets take a single class hierarchy. Lets say a User system? In this User system I have a UserService that provides me with the User objects, its like a DataMapper. And those users have points(doesn't matter what kind). These points are retrieved from a different site.
How would you do this? Where would you put the retrieval from the points? Seen your stand of view I would guess in UserService? Or the User superclass?
So what is the User hierarchy? UserService sounds like a factory so wouldn't be part of the hierarchy, and I'm not sure why the points coming from 'a different site' is relevant. You haven't described enough about the User super/subclasses and the points for me to answer the question.
My point is simply that when you have a number of siblings in a hierarchy that use common implementation and data, you should look to minimise the redundancy by pushing up the
common code and data to the superclass where possible/practical. It's a standard refactoring technique.
So if all User subclasses (UserA, UserB, UserC) have 'points' members, and have some common method implementations to manage these members, the points and the common methods (e.g. accessors & basic mutators) should be pushed up to the User superclass. IOW if all sibling subclasses have data X and non-polymorphic method Y, X and Y should be in the superclass. The subclasses then represent only the specialisations of the superclass.
There are many variations on the theme, e.g. the Template Method pattern for when partial polymorphism is required, but it's pretty standard stuff.
I get the feeling we're talking at cross-purposes in some way...