composite there are two fundamental approaches to dealing with the relationship between collection of actions and hierarchy of object types first consider the typical procedural approach say we have base class for page layout entitieswith subclass hierarchy to define specific subtypes (pagecolumnsrowsfigurescharactersetc and say there are actions to be performed on collection of such objects (such as rendering the objects to the screenthe procedural design approach is for each action to be implemented as method that takes as parameter pointer to the base class type each such method will traverse through the collection of objectsvisiting each object in turn each method contains something like case statement that defines the details of the action for each subclass in the collection ( pagecolumnrowcharacterwe can cut the code down some by using the visitor design pattern so that we only need to write the traversal onceand then write visitor subroutine for each action that might be applied to the collection of objects but each such visitor subroutine must still contain logic for dealing with each of the possible subclasses in our page composition applicationthere are only few activities that we would like to perform on the page representation we might render the objects in full detail or we might want "rough draftrendering that prints only the bounding boxes of the objects if we come up with new activity to apply to the collection of objectswe do not need to change any of the code that implements the existing activities but adding new activities won' happen often for this application in contrastthere could be many object typesand we might frequently add new object types to our implementation unfortunatelyadding new object type requires that we modify each activityand the subroutines implementing the activities get rather long case statements to distinguish the behavior of the many subclasses an alternative design is to have each object subclass in the hierarchy embody the action for each of the various activities that might be performed each subclass will have code to perform each activity (such as full rendering or bounding box renderingthenif we wish to apply the activity to the collectionwe simply call the first object in the collection and specify the action (as method call on that objectin the case of our page layout and its hierarchical collection of objectsthose objects that contain other objects (such as row objects that contains letterswill call the appropriate method for each child if we want to add new activity with this organizationwe have to change the code for every subclass but this is relatively rare for our text compositing application in contrastadding new object into the subclass hierarchy (which for this application is far more likely than adding new rendering functionis easy adding new subclass does not require changing