Design Patterns Part IV (TIC++V2:C10) Yingcai Xiao 10/01/08.

Slides:



Advertisements
Similar presentations
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
Advertisements

Design Patterns CMPS Design Patterns Consider previous solutions to problems similar to any new problem ▫ must have some characteristics in common.
Design Patterns Copyright © Vyacheslav Mukhortov, Nikita Nyanchuk-Tatarskiy, Copyright © INTEKS LLC,
Introduction To System Analysis and Design
Dept. of Computer Engineering, Amirkabir University of Tech. 1 Design Patterns Dr. Noorhosseini Introduction.
Algorithm Programming Structural Design Patterns Bar-Ilan University תשס " ו by Moshe Fresko.
Chapter 22 Object-Oriented Design
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Proxy Design Pattern (1) –A structural design pattern.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Proxy Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
CIT241 Prerequisite Knowledge ◦ Variables ◦ Operators ◦ C++ Syntax ◦ Program Structure ◦ Classes  Basic Structure of a class  Concept of Data Hiding.
Client/Server Software Architectures Yonglei Tao.
Introduction To System Analysis and design
Design Patterns Discussion of pages: xi-11 Sections: Preface, Forward, Chapter
Chapter 10 Architectural Design
Design Patterns.
Introduction to Object-oriented programming and software development Lecture 1.
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:
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Introduction To System Analysis and Design
Powerpoint Templates Page 1 Powerpoint Templates What is Design Patterns ? by Indriati Teknik Informatika – UB.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
In the name of Allah The Proxy Pattern Elham moazzen.
OOP Class Lawrence D’Antonio Lecture 3 An Overview of C++
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Structural Design Patterns
ECE450S – Software Engineering II
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.
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.
Structural Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
Proxy.
Proxy Design Pattern By:Diksha Agarwal.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Design Pattern Catalog - Page L3-1 PS95&96-MEF-L10-1 Dr. M.E. Fayad Creationa.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Design Patterns Introduction
1 Advanced Object-oriented Design – Principles and Patterns Structural Design Patterns.
Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it by creating a representative object.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Proxy Pattern. What’s a Proxy? A remote proxy acts as a local representative of a remote object Remote Object: instantiated in a different JVM heap (a.
The Proxy Pattern (Structural) ©SoftMoore ConsultingSlide 1.
Fusion Design Overview Object Interaction Graph Visibility Graph Class Descriptions Inheritance Graphs Fusion: Design The overall goal of Design is to.
Software Design and Architecture Muhammad Nasir Structural Design Patterns
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
1 Lecture Material Design Patterns Visitor Client-Server Factory Singleton.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Design Patterns – Group 2 Iterator, Proxy, Adapter, Decorator.
Chapter 0: Introduction
Design Patterns: MORE Examples
Software Design Patterns
Design Patterns Lecture part 2.
Introduction to Design Patterns
Review: Two Programming Paradigms
More Design Patterns 1.
Design Patterns Satya Puvvada Satya Puvvada.
More Design Patterns 1.
Advanced Programming Behnam Hatami Fall 2017.
Informatics 122 Software Design II
Overview of C++ Polymorphism
Informatics 122 Software Design II
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.
Presentation transcript:

Design Patterns Part IV (TIC++V2:C10) Yingcai Xiao 10/01/08

Design Patterns (What?) The original paper by the gang of four ns/Docs/orig-patterns-paper.pdf Design Patterns are devices that allow designers to share knowledge about their design. Design patterns identify, name, and abstract common themes in object-oriented design. idea reuse vs. code reuse.

Characteristics of a Design Pattern smart: elegant solutions that would not occur to a novice immediately generic: independent of specific system characteristics well-proven: identified from successful real, object-oriented systems simple: involve only a handful of classes

More Characteristics reusable: reuse at the design level, generic, well-documented object-oriented: uses classes, objects, generalization, and polymorphism

Constructing a Design Pattern name problem description: when pattern is to be used and which problem it attempts to solve solution: classes and objects, their structure, and dynamic collaboration consequences: results and trade-offs of applying the pattern

Types of Patterns (Purpose) Categorize patterns by what they do. creational: deal with the process of object creation structural: deal with the composition of classes or objects behavioral: describe ways in which classes or objects interact and allocate responsibilities

Types of Patterns (Scope) Scope specifies whether a pattern applies primarily to classes or to objects. Class scope:: deals with relationship between classes, established through inheritance. (static) Object scope: deals with object relationship, established through inclusion and usage. (dynamic)

Design Pattern Space

Example: Proxy Pattern Proxy: provides a surrogate to hide the real object behind. Applications: 1.remote proxy: to represent a remote object locally for easy and efficient coding (e.g. Java RMI and.NET Remoting) 2.protection proxy: to control the access to the real object (e.g. a proxy server hides the real server behind the firewall) 3.virtual proxy: to defer the expansive actions creating the real object. 4.smart reference: replacement for bare pointer that performs additional actions when an object is accessed

Example: Virtual Proxy from the original paper by the gang of four using OMT Notation (object diagram) Referes to (virtual representation)

Class Diagram of the Virtual Image Proxy

General Structure of a Proxy Class Diagram Object Diagram

Components of a Proxy Proxy: –maintains a reference to let proxy access the real subject –provides an interface identical to Subject’s so a proxy can be substituted for the real subject –controls access to the real subject; may be responsible for creating and deleting it

More Participants Subject: –defines the common interface for RealSubject and Proxy so a Proxy can be used anywhere a RealSubject is expected RealSubject: –defines the real object that the proxy represents

Collaborations Proxy forwards request to RealSubject when appropriate, depending on the kind of proxy

Sequence Diagram

Collaboration Diagram

Consequences proxy pattern introduces a level of indirection when accessing an object –a remote proxy can hide the fact that an object resides in a different address space –a virtual proxy can perform optimizations such as creating an object on demand –protection proxies and smart references allow additional tasks when an object is referenced

Implementation A proxy can exploit the following features: Java: use interface and implementation. C++: use virtual functions and overloading the member access operators. Smalltalk: use doesNotUnderstand, which supports automatic forwarding of requests Proxy doesn’t have to know the type of the real object (upcasted to Object in Java)

Sample Code in Java public class Proxy implements Subject { RealSubject refersTo; public void Request ( ) { if (refersTo = = null) refersTo = new RealSubject ( ); refersTo.Request ( ); }

Known Uses Stubs in Java RMI. Proxy server in networking NEXTSTEP uses proxies as local representatives for objects that may be distributed Proxies in Smalltalk to access remote objects

Related Patterns adapter: provides a different interface to the object it adapts; proxy provides the same interface as its subject decorator: adds one or more responsibilities to an object; proxy controls access to an object a protection proxy might be implemented exactly like a decorator

Proxy Example in C++ class ProxyBase { public: virtual void f() = 0; virtual void g() = 0; virtual void h() = 0; virtual ~ProxyBase() {} }; class Implementation : public ProxyBase { public: void f() { cout << "Implementation.f()" << endl; } void g() { cout << "Implementation.g()" << endl; } void h() { cout << "Implementation.h()" << endl; } };

Proxy Example in C++ class Proxy : public ProxyBase { ProxyBase* implementation; public: Proxy() { implementation = new Implementation(); } ~Proxy() { delete implementation; } // Forward calls to the implementation: void f() { implementation->f(); } void g() { implementation->g(); } void h() { implementation->h(); } }; int main() { Proxy p; p.f(); p.g(); p.h(); } ///:~