CSC/ECE 517 Fall 2010/ch7 7e ab

From Expertiza_Wiki
Jump to navigation Jump to search

Protected Variations Pattern

Description

The Protected Variations pattern is a specific example of a GRASP design pattern. It is very broad in its scope. Any object that presents a potential instability within the system due to variations of type is implemented with an interface and polymorphism (discussed in chapter 3) is used to wrap the type.[2] The interface could be a small enough to cover only one method or a very broad piece of the total subsystem.[1]


The basic object-oriented programming concepts of data encapsulation, interfaces, and polymorphism are all mechanisms that are present in the programming languages for similar reasons as the Protected Variations pattern.[3] The variations that are addressed could be data type, data format, different calculations, different object types, etc.

Examples

Document Plugin

Consider the example of an editor that is designed to open and edit different file types, as shown in Figure 1. The document type can be implemented as a type in the core application and document plugins can be designed to implement the interface for specific document types. As new document types are required, the responsibility for supporting the variations is shifted externally to the document plugin.

Figure 1. Document Plugin

In this case, the Protected Variations pattern is similar to the Adapter pattern.


Medical Data Printing

A medical data reporting system (Figure 2) is developed to take in different types of medical test results and print the results to a report. Different medical results may need to be handled in different ways, with some being formatted as numbers, some indicating a pass fail, some represented on a graph, etc. The medical result could be wrapped in an interface by the reporting system and implemented for each result type.

Figure 2. Medical Report System


Advantages

•New implementations of a particular module to handle a specific variation can be added to the software without impacting client software.[3]

•Coupling between different parts of the software system are lowered.[3][4]

•The cost of changes to the system can be lowered by ensuring that new variations can be supported by only adding a new implementation of the interface.[3]

•Extensions required for new variations are easy to add.[3]

Disadvantages

• Increases the complexity of the design by requiring the interface and implementations to be separate

• Forces the programmer to spend extra development time during initial programming development to ensure that the interface is generic enough to handle future implementations


References

[1] http://web.cs.wpi.edu/~gpollice/cs4233-a05/CourseNotes/maps/class4/ProtectedVariations.html

[2] http://en.wikipedia.org/wiki/GRASP_(object-oriented_design)#Protected_Variations

[3] http://www.objectsbydesign.com/books/larman_notes/6-DesignAndImplementationTechniques.html

[4] Craig Larman. Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development (3rd Edition). Prentice Hall, Upper Saddle River, NJ, 2004