7 Patterns-442-12-by6

Black box vs white box reuse black box relies on

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ation) Structure of a Lexi document Goals: 1. Storage of text and graphics in document 2. Generate visual display 3. Maintain information about location of display elements Caveats: 1. Must treat various kinds of objects (e.g., text, pictures, graphics) uniformly for client s beneGit 2. Must treat single stored objects (e.g., characters) and groups of objects (e.g., lines of text) uniformly 31 32 Case study Case study Glyph Draw(window) Intersect(point) Insert(Glyph*,int) Structure of a Lexi document Solution 1. DeGine abstract class Glyph for all displayed objects Glyph responsibilities: Know how to draw self Know what space occupied by self Know children and parent of self 2. Use recursive composition for deGining and handling complex objects DeGine composition of Glyph instances, also as Glyph instances 33 ... Glyph class diagram Rectangle ... Character ... Polygon ... Row ... 34 Pattern Pattern Component Operation() Add(Component) Remove(Component) Children() The Composite pattern Motivation: Support recursive composition in such a way that a client need not know the difference between a single and a composite object (as with Glyphs) Applicability: Dealing with hierarchically-organized objects (e.g., columns containing rows containing words ...) Structure: Same as previous picture 35 Composite class diagram Leaf Operation() Composite Operation() Remove(Component) Add(Component) Children() children forall c in children() do { c->operation(); } 36 Pattern Pattern Composite pattern (cont Consequences: d) Composite pattern (cont Implementation Issues: 1. Parent references d) 1. DeGine class hierarchies consisting of simple and composite objects 2. Simplify clients 3. Extensibility (clients do not have to be modiGied) 4. Too general a pattern? (makes it difGicult to to restrict functionality of concrete leaf subclasses) 37 Facilitate traversal of hierarchy 2. Sharing components Save space, but at the price of ncreased programming complexity (e.g., difGicult to implement with a single parent) 38 Pattern...
View Full Document

Ask a homework question - tutors are online