chap data structures and algorithms layout for document the letter "cmight reasonably be represented by an object that describes that character' strokes and bounding box howeverwe don' want to create separate "cobject everywhere in the document that "cappears the solution is to allocate single copy of the shared representation for "cobject thenevery place in the document that needs "cin given fontsizeand typeface will reference this single copy the various instances of references to "care called flyweights flyweight includes the reference to the shared informationand might include additional information specific to that instance we could imagine describing the layout of text on page by using tree structure the root of the tree is node representing the page the page has multiple child nodesone for each column the column nodes have child nodes for each row and the rows have child nodes for each character these representations for characters are the flyweights the flyweight includes the reference to the shared shape informationand might contain additional information specific to that instance for exampleeach instance for "cwill contain reference to the shared information about strokes and shapesand it might also contain the exact location for that instance of the character on the page flyweights are used in the implementation for the pr quadtree data structure for storing collections of point objectsdescribed in section in pr quadtreewe again have tree with leaf nodes many of these leaf nodes (the ones that represent empty areascontain the same information these identical nodes can be implemented using the flyweight design pattern for better memory efficiency visitor given tree of objects to describe page layoutwe might wish to perform some activity on every node in the tree section discusses tree traversalwhich is the process of visiting every node in the tree in defined order simple example for our text composition application might be to count the number of nodes in the tree that represents the page at another timewe might wish to print listing of all the nodes for debugging purposes we could write separate traversal function for each such activity that we intend to perform on the tree better approach would be to write generic traversal functionand pass in the activity to be performed at each node this organization constitutes the visitor design pattern the visitor design pattern is used in sections (tree traversaland (graph traversal