Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

GoF Structural Patterns-Object-Oriented Design-Lecture 21 Slides-Computer Engineering, Slides of Object Oriented Analysis and Design

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

2011/2012

Uploaded on 02/19/2012

hester
hester 🇮🇷

4.5

(13)

85 documents

1 / 25

Toggle sidebar

Related documents


Partial preview of the text

Download GoF Structural Patterns-Object-Oriented Design-Lecture 21 Slides-Computer Engineering and more Slides Object Oriented Analysis and Design in PDF only on Docsity!

Department of Computer Engineering

Sharif University of Technology

Object-Oriented Design

Lecturer: Raman Ramsin

Lecture 21

GoF Design Patterns – Structural

Department of Computer Engineering

Sharif University of Technology

GoF Structural Patterns  Class/ObjectAdapter: Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.  ObjectBridge: 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

Sharif University of Technology

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

Sharif University of Technology

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

Sharif University of Technology

Adapter (Class): Structure

Department of Computer Engineering

Sharif University of Technology

Adapter (Object): Structure

Department of Computer Engineering

Sharif University of Technology

Bridge  Intent:  Decouple an abstraction from its implementation so that the two can vary independently.

Department of Computer Engineering

Sharif University of Technology

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

Sharif University of Technology

Bridge: Structure

Department of Computer Engineering

Sharif University of Technology

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

Sharif University of Technology

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

Sharif University of Technology

Composite: Structure

Department of Computer Engineering

Sharif University of Technology

Composite: Typical Object Structure

Department of Computer Engineering

Sharif University of Technology

Decorator  Intent:  Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.

Department of Computer Engineering

Sharif University of Technology

Decorator: Class Hierarchy

Department of Computer Engineering

Sharif University of Technology

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

Sharif University of Technology

Decorator: Structure

Department of Computer Engineering

Sharif University of Technology

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

Sharif University of Technology

Façade: Class Hierarchy

Department of Computer Engineering

Sharif University of Technology

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

Sharif University of Technology

Proxy  Intent:  Provide a surrogate or placeholder for another object to control access to it.

Department of Computer Engineering

Sharif University of Technology

Proxy: Class Hierarchy

Department of Computer Engineering

Sharif University of Technology

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

Sharif University of Technology

Proxy: Structure

Department of Computer Engineering

Sharif University of Technology

Reference  Gamma, E., Helm, R., Johnson, R., and Vlissides, J., Design Patterns: Elements of Reusable Object-oriented Software. Addison-Wesley, 1995.