Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
GoF Structural Patterns, Adapter, Bridge, Composite, Decorator, Facade, Proxy, UML, Structural Patterns, Raman Ramsin, Lecture Slides, Object Oriented Design, Department of Computer Engineering, Sharif University of Technology, Iran.
Typology: Slides
1 / 25
Department of Computer Engineering
Department of Computer Engineering
GoF Structural Patterns Class/Object Adapter: Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces. Object Bridge: Decouple an abstraction from its implementation so that the two can vary independently. Composite: Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly. Decorator: Attach additional responsibilities to an object dynamically. Façade: Provide a unified interface to a set of interfaces in a subsystem. Flyweight: Use sharing to support large numbers of fine-grained objects efficiently. Proxy: Provide a surrogate or placeholder for another object to control access to it.
Department of Computer Engineering
Adapter Intent: Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.
Department of Computer Engineering
Adapter: Applicability Use the Adapter pattern when you want to use an existing class, and its interface does not match the one you need. you want to create a reusable class that cooperates with unrelated or unforeseen classes, that is, classes that don't necessarily have compatible interfaces. (object adapter only) you need to use several existing subclasses, but it's impractical to adapt their interface by subclassing every one. An object adapter can adapt the interface of its parent class.
Department of Computer Engineering
Adapter (Class): Structure
Department of Computer Engineering
Adapter (Object): Structure
Department of Computer Engineering
Bridge Intent: Decouple an abstraction from its implementation so that the two can vary independently.
Department of Computer Engineering
Bridge: Applicability Use the Bridge pattern when you want to avoid a permanent binding between an abstraction and its implementation; for example, when the implementation must be selected or switched at run-time. both the abstractions and their implementations should be extensible by subclassing; combine different abstractions and implementations and extend them independently. changes in the implementation of an abstraction should have no impact on clients; that is, their code should not have to be recompiled. (C++) you want to hide the implementation of an abstraction completely from clients. In C++ the representation of a class is visible in the class interface. you want to share an implementation among multiple objects and this fact should be hidden from the client.
Department of Computer Engineering
Bridge: Structure
Department of Computer Engineering
Composite Intent: Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.
Department of Computer Engineering
Composite: Applicability Use the Composite pattern when you want to represent whole-part- hierarchies of objects. you want clients to be able to ignore the difference between compositions of objects and individual objects. Clients will treat all objects in the composite structure uniformly.
Department of Computer Engineering
Composite: Structure
Department of Computer Engineering
Composite: Typical Object Structure
Department of Computer Engineering
Decorator Intent: Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
Department of Computer Engineering
Decorator: Class Hierarchy
Department of Computer Engineering
Decorator: Applicability Use the Decorator pattern to add responsibilities to individual objects dynamically and transparently, that is, without affecting other objects. for responsibilities that can be withdrawn. when extension by subclassing is impractical. Sometimes a large number of independent extensions are possible and would produce an explosion of subclasses.
Department of Computer Engineering
Decorator: Structure
Department of Computer Engineering
Façade Intent: Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.
Department of Computer Engineering
Façade: Class Hierarchy
Department of Computer Engineering
Façade: Applicability Use the Façade pattern when you want to provide a simple interface to a complex subsystem. there are many dependencies between clients and the implementation classes of an abstraction. you want to layer your subsystems. Use a facade to define an entry point to each subsystem level.
Department of Computer Engineering
Proxy Intent: Provide a surrogate or placeholder for another object to control access to it.
Department of Computer Engineering
Proxy: Class Hierarchy
Department of Computer Engineering
Proxy: Applicability Use the Proxy pattern when a surrogate is needed: Remote proxy: provides a local representative for an object in a different address space. Virtual proxy: creates expensive objects on demand. Protection proxy: controls access to the original object. Smart reference: a replacement for a bare pointer that performs additional actions when an object is accessed: counting the number of references to the real object so that it can be freed when there are no more references. loading a persistent object into memory when it's first referenced. checking that the real object is locked before it's accessed to ensure that no other object can change it.
Department of Computer Engineering
Proxy: Structure
Department of Computer Engineering
Reference Gamma, E., Helm, R., Johnson, R., and Vlissides, J., Design Patterns: Elements of Reusable Object-oriented Software. Addison-Wesley, 1995.