1

As a proxy for something real I am working on, consider building a model. We'd have a Parts class representing model parts, complete with methods to manufacture the part based on given parameters, to validate, etc. We have a Glue class which does much the same, and a ModelBuilder class.

I can manufacture my glue and parts with nice encapsulation. Then I pass my PartsInstance and my GlueInstance to my ModelBuilder as parameters. Here's where everything falls apart. I can tell my ModelBuilder to build, but to do so, it needs access to the data in the Parts (and maybe the Glue). I may for instance need to know where the corner or center of PartsInstance.Part[0] is in order to properly build.

I'm in a quandary here because it seems the Tell, Don't Ask camp would say that the part should build itself somehow. But that doesn't make sense to me. A part is a part, not the whole model. That's what should build itself. The ModelBuilder could be quite complex, and it's possible that the Parts might be used somewhere else. On the other hand, I'm inquiring as to the state of the PartsInstance object and then making a decision based on that state. Furthermore, the decision may not be something that fits solely inside the Parts concept anyway. It may involve the type of Glue I've chosen.

How can I construct or rework this example so that it doesn't violate encapsulation?

Fadecomic
  • 1,220
  • 1
  • 10
  • 23

0 Answers0