Weitere Àhnliche Inhalte
Ăhnlich wie Design Patterns - 03 Composite and Flyweight Pattern (20)
KĂŒrzlich hochgeladen (20)
Design Patterns - 03 Composite and Flyweight Pattern
- 3. Definition The composite pattern describes that a group of objects are to be treated in the same way as a single instance of an object.(wikipedia) © Prafulla Paraskar 2010
- 5. Composite Pattern â Explained (2/2) Arranges structured hierarchies so that single components and groups of components can be treated in the same way. Makes easier to add new components. Makes client code simpler, since they do not have to know if they are dealing with one or more components. Typical operations on the components include add, remove, display, find and group. © Prafulla Paraskar 2010
- 7. Composite Pattern â Real World Samples Files and folders in Windows Organization Tree Arithmetic Expressions like (2 + 4) * ( 5 + 6) Generic containers in .NET framework like list, queue, stack help implement the composite pattern. © Prafulla Paraskar 2010
- 9. To treat all objects in a composite uniformly.© Prafulla Paraskar 2010
- 11. Definition The Flyweight pattern is a pattern for sharing objects, where each instance does not contain its own state but stores it externally. This allows efficient sharing of objects to save space when there are many instances but only a few different types. (James W. Cooper â C# Design Patterns) © Prafulla Paraskar 2010
- 12. Flyweight Pattern â Explained (1/3) Designing objects down to the lowest levels of system "granularityâ provides optimal flexibility , but can be unacceptably expensive in terms Row objects a p p a r e n t Row objects Character object Column object © Prafulla Paraskar 2010
- 13. Flyweight Pattern â Explained (2/3) column row row row a f e d c b g l k j i h Flyweight pool © Prafulla Paraskar 2010
- 14. Flyweight Pattern â Explained (3/3) Useful in cases where large number of objects (flyweights)required to provide âfine grain accessâ to the system. Characteristics of flyweights are divided into intrinsic (inseparable) e.g. identity and extrinsic (separable) e.g. shared resource. Shared resource is taken care by a directory which manages enrollment of participant and provides on demand access to shared resources. Flyweights can only be created with help of a factory to enforce enrollment and sharing of resources. © Prafulla Paraskar 2010
- 16. Flyweight Pattern â Real World Samples Thumbnail representation of images in windows explorer. Order processing system where the items are relatively similar and differ only in certain characteristics. Representation of files and folders in windows explorer. Individual cells in a spreadsheet program. © Prafulla Paraskar 2010