chap data structures and algorithms any of the existing subclasses it merely requires that we define the behavior of each activity that can be performed on that subclass this second design approach of burying the functional activity in the subclasses is called the composite design pattern detailed example for using the composite design pattern is presented in section strategy our final example of design pattern lets us encapsulate and make interchangeable set of alternative actions that might be performed as part of some larger activity again continuing our text compositing exampleeach output device that we wish to render to will require its own function for doing the actual rendering that isthe objects will be broken down into constituent pixels or strokesbut the actual mechanics of rendering pixel or stroke will depend on the output device we don' want to build this rendering functionality into the object subclasses insteadwe want to pass to the subroutine performing the rendering action method or class that does the appropriate rendering details for that output device that iswe wish to hand to the object the appropriate "strategyfor accomplishing the details of the rendering task thuswe call this approach the strategy design pattern the strategy design pattern will be discussed further in therea sorting function is given class (called comparatorthat understands how to extract and compare the key values for records to be sorted in this waythe sorting function does not need to know any details of how its record type is implemented one of the biggest challenges to understanding design patterns is that many of them appear to be pretty much the same for exampleyou might be confused about the difference between the composite pattern and the visitor pattern the distinction is that the composite design pattern is about whether to give control of the traversal process to the nodes of the tree or to the tree itself both approaches can make use of the visitor design pattern to avoid rewriting the traversal function many timesby encapsulating the activity performed at each node but isn' the strategy design pattern doing the same thingthe difference between the visitor pattern and the strategy pattern is more subtle here the difference is primarily one of intent and focus in both the strategy design pattern and the visitor design patternan activity is being passed in as parameter the strategy design pattern is focused on encapsulating an activity that is part of larger processso that different ways of performing that activity can be substituted the visitor design pattern is focused on encapsulating an activity that will be performed on all members of collection so that completely different activities can be substituted within generic method that accesses all of the collection members