Composite and Related Patterns Kirk Scott. The pitohui, a poisonous bird of New Guinea.
-
Upload
silvia-young -
Category
Documents
-
view
217 -
download
3
Transcript of Composite and Related Patterns Kirk Scott. The pitohui, a poisonous bird of New Guinea.
![Page 1: Composite and Related Patterns Kirk Scott. The pitohui, a poisonous bird of New Guinea.](https://reader035.fdocuments.net/reader035/viewer/2022072006/56649f4f5503460f94c71e97/html5/thumbnails/1.jpg)
Composite and Related Patterns
Kirk Scott
![Page 2: Composite and Related Patterns Kirk Scott. The pitohui, a poisonous bird of New Guinea.](https://reader035.fdocuments.net/reader035/viewer/2022072006/56649f4f5503460f94c71e97/html5/thumbnails/2.jpg)
The pitohui, a poisonous bird of New Guinea
![Page 3: Composite and Related Patterns Kirk Scott. The pitohui, a poisonous bird of New Guinea.](https://reader035.fdocuments.net/reader035/viewer/2022072006/56649f4f5503460f94c71e97/html5/thumbnails/3.jpg)
• This is an introductory unit.• These are the units/chapters belonging to this
section of the course:• Unit 25, Composite, book chapter 5• Unit 26, Chain of Responsibility, book chapter
12• Unit 27, Interpreter, book chapter 25• Unit 28, Visitor, book chapter 29
![Page 4: Composite and Related Patterns Kirk Scott. The pitohui, a poisonous bird of New Guinea.](https://reader035.fdocuments.net/reader035/viewer/2022072006/56649f4f5503460f94c71e97/html5/thumbnails/4.jpg)
• What will be given next is an extremely brief overview of these topics.
• You will find that the composite design pattern has a lot in common with trees
• Chain of responsibility, interpreter, and visitor all follow naturally, because interesting examples of those patterns can be built on top of composites/trees
![Page 5: Composite and Related Patterns Kirk Scott. The pitohui, a poisonous bird of New Guinea.](https://reader035.fdocuments.net/reader035/viewer/2022072006/56649f4f5503460f94c71e97/html5/thumbnails/5.jpg)
Composite
• Book definition:• The intent of the Composite pattern is to let
clients treat individual objects and compositions of objects uniformly
• Comment mode on:• A composite can consist of one or more
components• Each component may be a single item or
another composite
![Page 6: Composite and Related Patterns Kirk Scott. The pitohui, a poisonous bird of New Guinea.](https://reader035.fdocuments.net/reader035/viewer/2022072006/56649f4f5503460f94c71e97/html5/thumbnails/6.jpg)
• In the verbal description above you may recognize the elements of a definition of a tree-like structure
• It is reminiscent of directory structures which can contain individual files as well as other directories
• This pattern has a distinctive UML diagram.• See the next overhead
![Page 7: Composite and Related Patterns Kirk Scott. The pitohui, a poisonous bird of New Guinea.](https://reader035.fdocuments.net/reader035/viewer/2022072006/56649f4f5503460f94c71e97/html5/thumbnails/7.jpg)
![Page 8: Composite and Related Patterns Kirk Scott. The pitohui, a poisonous bird of New Guinea.](https://reader035.fdocuments.net/reader035/viewer/2022072006/56649f4f5503460f94c71e97/html5/thumbnails/8.jpg)
Chain of Responsibility
• Book definition:• The intent of the Chain of Responsibility pattern is
to avoid coupling the sender of a request to its receiver, by giving more than one object a chance to handle the request.
• Comment mode on:• If a set of objects is linked together, you may call a
method on one.• Potentially that one calls a method on the next in
the chain, and so on down the line
![Page 9: Composite and Related Patterns Kirk Scott. The pitohui, a poisonous bird of New Guinea.](https://reader035.fdocuments.net/reader035/viewer/2022072006/56649f4f5503460f94c71e97/html5/thumbnails/9.jpg)
Interpreter
• Book definition:• The intent of the Interpreter pattern is to let you
compose executable objects according to a set of composition rules that you define.
• Comment mode on:• This directly parallels composite• Interpreters interpret commands• Commands can consist of single commands or
collections (composites) of commands
![Page 10: Composite and Related Patterns Kirk Scott. The pitohui, a poisonous bird of New Guinea.](https://reader035.fdocuments.net/reader035/viewer/2022072006/56649f4f5503460f94c71e97/html5/thumbnails/10.jpg)
Visitor
• Book definition:• The intent of Visitor is to let you define a new
operation for a hierarchy without changing the hierarchy classes.
• Comment mode on:• The relationship with composite is that the
hierarchy you define the operation for may be the component/leaf/composite hierarchy which generates a tree
![Page 11: Composite and Related Patterns Kirk Scott. The pitohui, a poisonous bird of New Guinea.](https://reader035.fdocuments.net/reader035/viewer/2022072006/56649f4f5503460f94c71e97/html5/thumbnails/11.jpg)
In Summary and Mnemonic Devices:
• Composite: = Tree• Chain of Responsibility: Think “Tree of
Responsibility”• Interpreter: Remember the analogy between
directory structures and program structures (routines and subroutines)
• Visitor: Visiting the branches and leaves of trees…
![Page 12: Composite and Related Patterns Kirk Scott. The pitohui, a poisonous bird of New Guinea.](https://reader035.fdocuments.net/reader035/viewer/2022072006/56649f4f5503460f94c71e97/html5/thumbnails/12.jpg)
The End