quote:Original post by risingdragon3
I suggest in this case to use get() / set() methods, which return a interface Engine.
I don''t regard that as good general advice either. The problem is twofold.
Firstly, ask yourself "why do we make data private in the first place?" Lots of accessors and mutators in a design can cause the same problems that public data causes. They reveal the internal structure of the class and allow clients to rely on that structure. Also, they are symptomatic of "mechanistic" design, where you are allowing the solution domain to drive and are ending up with interfaces semantically far removed from the problem domain, which is what you are *supposed* to be modelling after all. Don''t let the tail wag the dog - create interfaces based on the "business rules" that the class models.
Secondly, you''re recommending direct violation of the Law of Demeter, which I recommend folks try Googling for. Again, violating LoD makes a design rely on internal structure of classes - this time the composition of classes is revealed to the outside world.
The upshot of both of these problems is that you create yourself a design which is hard to change, where change is the only certainty of s/w development.