PowerPoint PresentationLesson ObjectivesStructural PatternsProxy Pattern: DefinitionProxy Pattern: StructureProxy Pattern: Structure (2)Document Editor ExampleSlide 8Remote ProxiesVirtual ProxiesProtection ProxiesSmart Reference ProxyProxy Pattern: Participants & CollaborationsProxy Pattern: ConsequencesProxy Pattern: Distinguishing AspectsProxy Pattern: Implementation Issues in C++ErrorProxy Example: How Errors are Used in the SystemErrorProxy DiagramUse of the ErrorProxyScenario Diagram WalkthroughSlide 21Composite Pattern: DefinitionComposite Pattern: ExampleComposite Pattern: StructureGraphic Application Example: Type HierarchyGraphic Application ExampleComposite Pattern: What it SolvesComposite Pattern: ParticipantsComposite Pattern: CollaborationsComposite Pattern: BenefitsComposite Pattern: Related PatternsSlide 32Adapter & Bridge: Common AttributesThe Differences Between an Adapter & a BridgeComposite & Decorator: Common AttributesDifference Between Composite & DecoratorDiscussion QuestionsCopyright © 1995-2004 Active Frameworks Inc. - All Rights Reserved - V2.0 More on Structural Patterns - Page L7-1PS95&96-MEF-L14-1Dr. M.E. FayadCreationalParadigm Shift, Inc.Software FactoryBehavioralStructuralLesson 7:More on Structural PatternsLesson 7:More on Structural PatternsObject-Object-OrientedOrientedDesignDesignPatternPatternssCopyright © 1995-2004 Active Frameworks Inc. - All Rights Reserved - V2.0 More on Structural Patterns - Page L7-2PS95&96-MEF-L14-2Dr. M.E. FayadLesson ObjectivesLesson ObjectivesObjectivesPresent the following Patterns:ProxyCompositeDiscuss in detail the structural patternsCopyright © 1995-2004 Active Frameworks Inc. - All Rights Reserved - V2.0 More on Structural Patterns - Page L7-3PS95&96-MEF-L14-3Dr. M.E. FayadStructural PatternsProxy Pattern•Topics–Proxy Definition–Structure–Document Editor Example–Proxy Properties–Applicability–Consequences–ErrorProxy ExampleCopyright © 1995-2004 Active Frameworks Inc. - All Rights Reserved - V2.0 More on Structural Patterns - Page L7-4PS95&96-MEF-L14-4Dr. M.E. FayadProxy Pattern: Definition•A Proxy is a surrogate or a placeholder for another object to control access to the real objects.•The Proxy pattern is applicable when there is a need for sophistication in a reference to an object. There is added function between a client and the intended subject object.•Sometimes the Proxy pattern is known as an Ambassador pattern (when dealing with distributed objects).Copyright © 1995-2004 Active Frameworks Inc. - All Rights Reserved - V2.0 More on Structural Patterns - Page L7-5PS95&96-MEF-L14-5Dr. M.E. FayadProxy Pattern: StructurerealSubject->Request();SubjectRequest()......RealSubjectRequest()ClientClassProxyRequest()UsesrealSubjectaClientObjectsubjectaSubjectProxyrealSubjectaRealSubjectInstance DiagramCopyright © 1995-2004 Active Frameworks Inc. - All Rights Reserved - V2.0 More on Structural Patterns - Page L7-6PS95&96-MEF-L14-6Dr. M.E. Fayad•The Subject defines the common interface for the RealSubject and Proxy.•The Proxy can be used any place a RealSubject is expected.•The RealSubject defines the real object that the Proxy represents.Proxy Pattern: Structure (2)Copyright © 1995-2004 Active Frameworks Inc. - All Rights Reserved - V2.0 More on Structural Patterns - Page L7-7PS95&96-MEF-L14-7Dr. M.E. FayadDocument Editor Exampleif (image == 0) image=Loadimage(fileName)image->Draw()GraphicItemDraw()GetEntent()Store()Load()RealSubjectfileNameextentDocumentEditorImageProxyimageRepextentItems Image(creates)Draw()GetEntent()Store()Load()Draw()GetEntent()Store()Load()if (image == 0) return extentreturn image->GetExtent()Copyright © 1995-2004 Active Frameworks Inc. - All Rights Reserved - V2.0 More on Structural Patterns - Page L7-8PS95&96-MEF-L14-8Dr. M.E. Fayad•Maintains the ability to access the real object, while screening requests for direct manipulation of the object•Provides an identical interface to the Subject so that it can be substituted for the Subject in any instance•Controls access to the Subject, even managing it•Has other responsibilities defined by the type of Proxy:–Remote Proxies–Virtual Proxies–Protection Proxies–Smart Reference ProxiesProxy Pattern PropertiesCopyright © 1995-2004 Active Frameworks Inc. - All Rights Reserved - V2.0 More on Structural Patterns - Page L7-9PS95&96-MEF-L14-9Dr. M.E. FayadRemote Proxies•Are responsible for encoding requests (with its accompanying arguments) to forward to its corresponding real object, which is found in another address space (Remote or Distributed Object).•This Proxy is an “Ambassador” to a distributed object.•This Proxy hides the fact from the user that the object is distributed.Copyright © 1995-2004 Active Frameworks Inc. - All Rights Reserved - V2.0 More on Structural Patterns - Page L7-10PS95&96-MEF-L14-10Dr. M.E. FayadVirtual Proxies•Cache information about the real object, so that they only access the object when it is absolutely necessary•This Proxy is used to access expensive objects, such as objects high in storage, access time, or another limit resource, created on demand.•Example: ImageProxyCopyright © 1995-2004 Active Frameworks Inc. - All Rights Reserved - V2.0 More on Structural Patterns - Page L7-11PS95&96-MEF-L14-11Dr. M.E. FayadProtection Proxies•Protect access to the original object•This means that screen users to access the real object or only allow access to a limited public interface•While the real object may have a private interface is then a subset of the real interface•Example: KernelProxies in the Choices Operating System that provide a protected access to operating system objectsCopyright © 1995-2004 Active Frameworks Inc. - All Rights Reserved - V2.0 More on Structural Patterns - Page L7-12PS95&96-MEF-L14-12Dr. M.E. FayadSmart Reference Proxy•A Smart Reference Proxy is a replacement for a bare pointer•A Smart Reference Proxy performs additional actions when an object is accessed:–Count the number of references to the real object so that it can be automatically freed when there are no more references–Create a transient representation for a persistent object that is loading the object into memory–Copy or write, that is, just increment the reference count when asked to copy
View Full Document