November Ron McFadyen1 Composite Pattern A composite is a group of objects in which some objects contain others; one object may represent groups, and another may represent an individual item, a leaf.
November Ron McFadyen2 Composite Pattern Generic UML class diagram Component Operation() Leaf Operation() Composite Operation() Other() * Client
November Ron McFadyen3 Composite Pattern Consider the handout from Refactoring by Martin Fowler “Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code yet improves its internal structure.” P 76 Long Method: “object programs … short methods” “the longer a procedure is, the more difficult it is to understand” “A heuristic we follow is that whenever we feel the need to comment something, we write a method instead” “How do you identify the clumps of code to extract? A good technique is to look for comments. They often signal a kind of semantic distance.”
November Ron McFadyen4 Composite Pattern Refactoring by Martin Fowler Figure 4.1. The composite structure of tests Test TestSuiteTestCase FileReaderTester junit.framework *
November Ron McFadyen5 Composite Pattern Junit is a testing framework for Java (If interested, see Any class that contains a test, must be subclassed from TestCase Tests can be grouped into test suites Pages illustrate how to use junit to manage a suite of tests We’ll look at an example for NextGenPOS