Structural Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.

Slides:



Advertisements
Similar presentations
JDBC Session 4 Tonight: Design Patterns 1.Introduction To Design Patterns 2.The Factory Pattern 3.The Facade Pattern Thursday & Next Tuesday: Data Access.
Advertisements

Matt Klein. Decorator Pattern  Intent  Attach Additional responsibilities to an object by dynamically. Decorators provide a flexible alternative to.
1 Structural Design Patterns - Neeraj Ray. 2 Structural Patterns - Overview n Adapter n Bridge n Composite n Decorator.
Flyweight: Structural Pattern Prepared by Galina Walters.
Imagine that you need to create a system to represent all of the cars in a city. You need to store the details about each car ( model, and year) and the.
Flyweight An Object Structural Design Pattern JM Imbrescia.
Design Patterns CS is not simply about programming
Façade Pattern Jeff Schott CS590L Spring What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance.
Design Patterns I 1. Creational Pattern Singleton: intent and structure Ensure a class has one instance, and provide a global point of access to it 2.
Design Patterns Part IV (TIC++V2:C10) Yingcai Xiao 10/01/08.
Algorithm Programming Structural Design Patterns Bar-Ilan University תשס " ו by Moshe Fresko.
Software Design and Documentation Individual Presentation: Composite Pattern 9/11/03.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Katie C. O’Shea Dennis T. Tillman 11 February 2K2 Flyweight.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VI Composite, Iterator, and Visitor Patterns.
Proxy Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Client/Server Software Architectures Yonglei Tao.
Design Patterns.
Smart Reference Proxy Provides additional actions whenever an object is referenced (e.g., counting the number of references to the object) Firewall Proxy.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
1 The Proxy Design Pattern Problem: Defer the cost of object creation and init. until actually used Applicability (possible contexts): – Virtual Proxy:
Design Patterns Part two. Structural Patterns Concerned with how classes and objects are composed to form larger structures Concerned with how classes.
Design Patterns: Structural Design Patterns
In the name of Allah The Proxy Pattern Elham moazzen.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
Facade Introduction. Intent Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the.
SDP Structural Pattern. SDP-2 Structural Patterns Concerned with how classes and objects are composed to form large structures Class Patterns use.
Structural Design Patterns
ECE450S – Software Engineering II
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IV Structural Patterns.
Where Do Surrogates Fit into This Proxy Pattern Observer Pattern Visitor Pattern By Kurt Rehwinkel.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns V More Structural Patterns.
02 - Structural Design Patterns – 2 Moshe Fresko Bar-Ilan University תשס"ח 2008.
Design Patterns Structural Patterns. Adapter Convert the interface of a class into another interface clients expect Adapter lets classes work together.
Proxy, Observer, Symbolic Links Rebecca Chernoff.
08 - StructuralCSC4071 Structural Patterns concerned with how classes and objects are composed to form larger structures –Adapter interface converter Bridge.
Proxy Design Pattern By:Diksha Agarwal.
FacadeDesign Pattern Provide a unified interface to a set of interfaces in a subsystem. Defines a high level interface that makes the subsystem easier.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Design Patterns By Mareck Kortylevitch and Piotreck Ratchinsky.
1 Advanced Object-oriented Design – Principles and Patterns Structural Design Patterns.
The Facade Pattern (Structural) ©SoftMoore ConsultingSlide 1.
Component Patterns – Architecture and Applications with EJB copyright © 2001, MATHEMA AG Component Patterns Architecture and Applications with EJB Markus.
The Flyweight Pattern (Structural) ©SoftMoore ConsultingSlide 1.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
CS 5150 Software Engineering Lecture 16 Program Design 3.
Design Patterns: Structural Design Patterns General and reusable solutions to common problems in software design Software University
The Proxy Pattern (Structural) ©SoftMoore ConsultingSlide 1.
COMPOSITE PATTERN NOTES. The Composite pattern l Intent Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients.
Software Design and Architecture Muhammad Nasir Structural Design Patterns
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Describe ways to assemble objects to implement a new functionality
Façade Pattern:.
Structural Patterns Structural patterns control the relationships between large portions of your applications. Structural patterns affect applications.
Software Design & Documentation
Introduction to Design Patterns
Software Design and Architecture
Flyweight Design Pattern
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Decorator Design Pattern
Design Patterns Satya Puvvada Satya Puvvada.
Object Oriented Design Patterns - Structural Patterns
UNIT-III Structural Design Patterns
Flyweight Pattern 1.
Structural Patterns: Adapter and Bridge
Software Design Lecture : 38.
Proxy Pattern Definition of “Proxy”: Authority or power to act for another Original Gang of Four pattern, much used Stands in for a “real object” (similar.
Software Design Lecture 10.
Message Passing Systems
Presentation transcript:

Structural Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class

Structural Patterns2 concerned with how classes and objects are composed to form larger structures Adapter interface converter Bridge decouple abstraction from its implementation Composite compose objects into tree structures, treating all nodes uniformly Decorator attach additional responsibilities dynamically –Façade provide a unified interface to a subsystem –Flyweight using sharing to support a large number of fine-grained objects efficiently –Proxy provide a surrogate for another object to control access

Structural Patterns3 Façade Provide a unified interface to a set of interfaces in a subsystem. –Façade defines a higher-level interface that makes the subsystem easier to use

Structural Patterns4 Façade

Structural Patterns5 Applicability you want a simple interface to a complex subsystem –Subsystems often get more complex as they evolve this makes the subsystem more reusable and easier to customize, but it also becomes harder to use for clients that don't need to customize it –A façade can provide a simple default view of the subsystem that is good enough for most clients Only clients needing more customizability will need to look beyond the façade there are many dependencies between clients and the implementation classes of an abstraction –Introduce a façade to decouple the subsystem from clients and other subsystems you want to layer your subsystems –Use a façade to define an entry point to each subsystem level

Structural Patterns6 Structure Façade –knows which subsystem classes are responsible for a request –delegates client requests to appropriate subsystem objects subsystem classes –implement subsystem functionality –handle work assigned by the Façade object –have no knowledge of the façade

Structural Patterns7 Consequences shields clients from subsystem components –reduces the # of objects clients see easier to use subsystem promotes weak coupling between the subsystem and its client –can vary the components of a subsystem without affecting clients –reduces compilation dependencies doesn't prevent applications from using subsystem classes if they need to. –you can choose between ease of use and generality

Structural Patterns8 Proxy Provide a surrogate or placeholder for another object to control access to it –e.g., on-demand image loading so that opening a document is fast

Structural Patterns9 Applicability whenever there is a need for a more versatile or sophisticated reference to an object than a simple pointer –A remote proxy provides a local representative for an object in a different address space –A virtual proxy creates expensive objects on demand –A protection proxy controls access to the original object. –Protection proxies are useful when objects should have different access rights –A smart reference is a replacement for a bare pointer that performs additional actions when an object is accessed counting the number of references to the real object (smart pointer) 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 –COW (copy-on-write)

Structural Patterns10 Structure Subject –defines the common interface for RealSubject and Proxy so that a Proxy can be used anywhere a RealSubject is expected RealSubject –defines the real object that the proxy represents

Structural Patterns11 Structure Proxy –maintains a reference that lets the proxy access the real subject –provides an interface identical to Subject's so that a proxy can by substituted for the real subject –controls access to the real subject and may be responsible for creating and deleting it remote proxies are responsible for encoding a request and its arguments and for sending the encoded request to the real subject in a different address space virtual proxies may cache additional information about the real subject so that they can postpone accessing it protection proxies check that the caller has the access permissions required to perform a request

Structural Patterns12 Flyweight Use sharing to support large numbers of fine-grained objects efficiently

Structural Patterns13 Applicability Use when: –An application uses a large number of objects –Storage costs are high because of the sheer quantity of objects –Most object state can be made extrinsic –Many groups of objects may be replaced by relatively few shared objects once extrinsic state is removed –The application doesn't depend on object identity Since flyweight objects may be shared, identity tests will return true for conceptually distinct objects

Structural Patterns14 Structure Flyweight –declares an interface through which flyweights can receive and act on extrinsic state

Structural Patterns15 Structure ConcreteFlyweight –implements the Flyweight interface and adds storage for intrinsic state, if any –must be sharable any state it stores must be intrinsic (independent of context)

Structural Patterns16 Structure UnsharedConcreteFlyweight –not all Flyweight subclasses need to be shared. –The Flyweight interface enables sharing; it doesn't enforce it

Structural Patterns17 Structure FlyweightFactory –creates and manages flyweight objects –ensures that flyweights are shared properly when a client requests a flyweight, the FlyweightFactory object supplies an existing instance or creates one, if none exists

Structural Patterns18 Structure Client –maintains a reference to flyweights –computes or stores the extrinsic state of flyweights

Structural Patterns19 Structure Clients should not instantiate ConcreteFlyweights directly. Clients must obtain ConcreteFlyweight objects exclusively from the FlyweightFactory object to ensure they are shared properly

Structural Patterns20 Consequences Flyweights introduce run-time costs associated with transferring, finding, and/or computing extrinsic state. Costs are offset by space savings –(which also save run-time costs) –depends on the reduction in the total number of instances that comes from sharing the amount of intrinsic state per object whether extrinsic state is computed or stored Often coupled with Composite to represent a hierarchical structure as a graph with shared leaf nodes –flyweight leaf nodes cannot store a pointer to their parent –parent pointer is passed to the flyweight as part of its extrinsic state profound effect on object collaboration

Structural Patterns21 Implementation Extrinsic State e.g., Document editor type style, –character font, type style, and colour. –store a map that keeps track of runs of characters with the same typographic attributes Shared Objects –FlyweightFactory can use an associative array to find existing instances. –need reference counting for garbage collection