7 Patterns-442-12-by6

code annotations rectangle getarea double width

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: itional object, called a proxy Clients access to protected object only through proxy Proxy keeps track of status or location of protected obj Image draw() getExtent() load() ... imageImp extent image ImageProxy draw() getExtent() load() ... fileName extent if (image == 0) { return extent;} else return image->getExtent(); Question: How do you make proxy transparent to clients? 17 if (image == 0) { image->load(fileName);} image->draw(); 18 Pattern Subject Request() ... Pattern Class diagram of Proxy pattern ... Object diagram of Proxy pattern aClient subject RealSubject Request() ... realSubject Proxy Request() ... status aProxy realSubject aRealSubject if (statusOK) realSubject->request(); else {...}; 19 20 Pattern Pattern Responsibilities of Proxy Maintain reference to object accessed Provide appropriate interface to clients (by delegating when necessary) Control access to the real object Kinds of proxies (and added resp.): -- remote (location of real object) -- virtual (cache information) -- protection (check access rights) Consequences of Proxy pattern Smart pointer applications One Proxy class for different object classes 21 22 Characterization Characterization Components of a Pattern (Go4) 1. Pattern name Identify this pattern; distinguish from other patterns DeGine a lexicon for OO design 2. Pattern alias -- also known as 3. Real-world example (motivation) 4. Context 5. Problem 6. Solution Typically English-based notation (e.g., CRC cards) 23 Components of a Pattern (cont 7. Structure d) Class (and possibly object) diagram in solution (usually OMT for historical reasons) 8. Interaction diagram (optional) 9. Consequences Advantages and disadvantages of pattern Ways to address residual design decisions 24 Characterization Components of a Pattern (cont 10. Implementation d) The Go4 s taxonomy of patterns Go4 Taxonomy The Go4 deGine 23 patterns differing in purpose (used for classiGication), level of abstraction, and granularity 1. Creational patterns (5) Describe how to create objects Often by delegation of responsibility from an abstract class to concrete subclasses 2. Structural patterns (7) Describe how to deGine data structures and their relations 3. Behavioral patterns (11) Describe object behavior and interactions among objects 25 26 Critical portion of plausible cod...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online