9548086042 for call girls in Indira Nagar with room service
Composite Design Pattern
1.
2. Design Patterns All well-structured object-oriented systems are full of patterns . If the common collaborations among the objects of a complex object-oriented system is paid careful and sufficient attention, it can yield an architecture that is smaller, simpler and far more understandable Creational Structural Behavioral Abstract Factory Builder Prototype Singleton etc. Adapter Bridge Composite Decorator Façade Proxy etc. Command Iterator Observer Strategy Interpreter Mediator etc.
3.
4.
5.
6.
7.
8.
9. A simple example May 23, 2007 Arithmetic expressions are Composites. An arithmetic expression consists of an operand, an operator ( +, -, *, / ) and another operand. The operand can be a number, or another arithmetic expression . Thus, 2 + 3 and (2 + 3) + (4 * 6) are both valid expressions.
11. Collaborations May 23, 2007 The clients handle a component through its general interface . A leaf directly executes the operations required, whereas a composite transfers the requests to its children.
12.
13. Example Continued… May 23, 2007 public void ls() { System.out.println(mName + “ ” ); for (int i=0; i<mFiles.size(); i++) { Object obj = mFiles.get(i); /* **** Recover the type of this object ****** */ if (obj.getClass().getName().equals( "Directory" )) ((Directory) obj).ls(); else ((File) obj).ls(); } } /* -- Some other methods here including add() -- */ } So here, we had to query the "type" of each object before attempting to process it, but it is not desirable .
14. Can we use Composite Pattern here ?? May 23, 2007 The key to this composite pattern is an interface (AbstractFile) that represents both primitives(File) and composites (Directory).
15.
16.
17. Another Example – Graphics Drawing May 23, 2007 In graphics applications, the user can group components to form larger components