When you find yourself trying to do too many unrelated things in a class, it’s time to split the class in two. For instance, you put the rules and conceptual behavior (the so-called business logic) in one class know as the model. You put visualization and display details in another class known as the view.
Often your model has parts and you want each of the parts to have an associated view. The view for the main model will have sub-views for each of the model’s parts. Thus we end up with a scenario like this:
How would you implement this scenario in your favorite language? Keep in mind the consequences of these for statements:
Also think about potentially desirable properties that do not necessarily follow:
What do you think of your implementation? Is it the sort of thing your language, libraries, and environment support nicely or is it the sort of thing that’s buggy and hard to get right? If its hard, what patterns, protocols, or tests do you use to make it easier?
Commentary