Thinking in Patterns: Step 2d (Facade)

Next, I need to verify if any of the remaining patterns create a context for each other. In this case, Facade and Adapter now clearly relate to different pieces of the design and are independent of each other. Therefore, I can apply them in whatever order I choose. I will arbitrarily pick the Facade to apply next, which results in Figure 12-10.

Figure 12-10. After applying the Bridge and Facade patterns.


Applying the Facade pattern means that I insert a facade between the V1 modules and the V1Imp object that is going to use them. V1Facade has simplified methods that relate to what V1Imp needs to do. Each method in V1Facade will look like a series of function calls on the V1 system.

The kind of information that I need in order to call these functions will determine how V1Imp is implemented. For example, when using V1, I need to tell it which model to use and what the Feature's ID is. All V1Imp objects that use the V1Facade will therefore need to know this information. Since this is implementation-specific information, it will need to know it itself, rather than getting it from the calling Feature. Thus, in a V1 system, each Feature will need its own V1Imp object (to remember system-specific information about the feature). I will go over this in more detail once the general architecture is completed.

Taking advantage of nongeneralities to debug code.

Earlier in this chapter, I mentioned that some of the methods of the implementation should only be called by certain Feature objects. I can take advantage of knowing what should be calling what to put checks in the code. I do not need to do this, and I may need to remove these checks if the rules change. Nevertheless, it can be useful the first time in.

For example, in the CAD/CAM solution, there are Features containing an implementation object. One of the implementation methods is getEdgeType. This only makes sense if a Feature is a slot or a cutout. Other Features do not have edge types. If I have implemented things properly, the getEdgeType method will never get called except by slots and cutouts. I can check that this happens by using an assert in the getEdgeType method that verifies that the calling Feature is of the appropriate type.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.91.252