Design Patterns Copyright © Vyacheslav Mukhortov, Nikita Nyanchuk-Tatarskiy, 2001-2004 Copyright © INTEKS LLC, 2003-2004.

Slides:



Advertisements
Similar presentations
Welcome to. Who am I? A better way to code Design Patterns ???  What are design patterns?  How many are there?  How do I use them?  When do I use.
Advertisements

Plab – Tirgul 12 Design Patterns
(c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.
Design Patterns CS is not simply about programming
Design Patterns. What are design patterns? A general reusable solution to a commonly occurring problem. A description or template for how to solve a problem.
Design Patterns Part IV (TIC++V2:C10) Yingcai Xiao 10/01/08.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
Chapter 22 Object-Oriented Design
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Design Patterns academy.zariba.com 1. Lecture Content 1.What are Design Patterns? 2.Creational 3.Structural 4.Behavioral 5.Architectural 6.Design Patterns.
More OOP Design Patterns
Proxy Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Vrije Universiteit amsterdamPostacademische Cursus Informatie Technologie Idioms and Patterns polymorphism -- inheritance and delegation idioms -- realizing.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Design Patterns.
Design patterns. What is a design pattern? Christopher Alexander: «The pattern describes a problem which again and again occurs in the work, as well as.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
CSSE 374: Introduction to Gang of Four Design Patterns
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Computing IV Singleton Pattern Xinwen Fu.
GoF: Document Editor Example Rebecca Miller-Webster.
CSE 403 Lecture 14 Design Patterns. Today’s educational objective Understand the basics of design patterns Be able to distinguish them from design approaches.
Patterns COM379 University of Sunderland James Malone.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
Structural Design Patterns
ECE450S – Software Engineering II
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared.
CS 4233 Review Feb February Review2 Outline  Previous Business – My.wpi.edu contains all grades to date for course – Review and contact.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Billy Bennett June 22,  Intent Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
CS212: Object Oriented Analysis and Design Lecture 38: Design Pattern-II.
Design Patterns Introduction
Design Patterns SE464 Derek Rayside images from NetObjectives.com & Wikipedia.
1 Chapter 5:Design Patterns. 2 What are design pattern?  Schematic description of design solution to recurring problems in software design and,  Reusable.
Advanced Object-oriented Design Patterns Creational Design Patterns.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns: MORE Examples
Abstract Factory Pattern
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
Software Design Patterns
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Factory Patterns 1.
Introduction to Design Patterns
Behavioral Design Patterns
Software Design and Architecture
Design Patterns with C# (and Food!)
object oriented Principles of software design
Abstract Factory Pattern
Design Patterns Satya Puvvada Satya Puvvada.
Software Engineering Lecture 7 - Design Patterns
Informatics 122 Software Design II
Structural Patterns: Adapter and Bridge
Design Patterns Imran Rashid CTO at ManiWeber Technologies.
Informatics 122 Software Design II
Presentation transcript:

Design Patterns Copyright © Vyacheslav Mukhortov, Nikita Nyanchuk-Tatarskiy, Copyright © INTEKS LLC,

Design pattern Design pattern is a solution to a problem, which occurs over and over again. Pattern elements: Name – a handle we use to describe a pattern in a word or two Problem – describes when to apply a pattern Solution – describes a set of design elements which solve a problem Consequences – benefits, disadvantages, constraints

Pattern types E. Gamma classification:  Creational patterns – abstract the instantiation process and make a system independent on how objects are created  Abstract Factory, Factory Method, Singleton  Structural patterns – solve objects composition problems  Adapter, Bridge, Decorator, Proxy  Behavioral patterns - algorithms and the assignment of responsibilities between objects  Chain of Responsibility, Command, Iterator, Observer, State, Strategy

Abstract Server Problem: - Button is not reusable in a context not involving a light

Solution Solution: break dependency between Button and Light by inserting an interface

Abstract Server Pattern Benefits: - decouples clients from their servers - can be changed without affecting clients - eliminates DIP violation

Adapter Problem: - Light already exists and can’t inherit from Device - Device might have messages activate/deactivate

Solution - use an adapter to convert one interface to another

Pattern: Adapter Also known as: Wrapper Benefits: - breaks dependency between client and server when server exists - allows different servers to be swapped in and out

Pattern: Adapter A variation, which allows server methods to be redefined

Abstract Client Problem: Server needs to send callback message to client GUI Button is not a reusable class Callback method makes Device unreusable

Solution Server provides interface for client to use

Pattern: Abstract Client Q: What package should contain AbstractClient class ? A: Server’s package

Adapted Client Problem: GUI library components (JButton) do not implement StateListener Solution: use Adapter pattern along with Abstract Client

Singleton Problem: How many database objects do we need in a simple program? Would it be a bad thing is someone mistakenly created more? Solution: prevent programmers from making objects. Make constructors private or protected. make the class responsible for making the one and only object

Singleton Use singleton when: there must be exactly one instance of a class it must be accessible to clients from anywhere inside the program: CompanyDb::Instance()->getEmployee(“Leha”); class CompanyDb { private: static CompanyDb* db; CompanyDb(); ~CompanyDb(); public: static CompanyDb* Instance() { if( 0 == db ) return db = new CompanyDb(); return db; } Employee* getEmployee( const char* name ); };

Monostate Solves the same problem as Singleton All members are static Constructors and destructor are private Class CompanyDb { private: Db db; CompanyDb(); public: static Employee* get Employee( const char* name ); } Db CompanyDb::db = Db( “CompanyName” ); Employee* CompanyDb::getEmployee( const char* name ) { return db.find( “Employee”, name ); } Employee* emp = CompanyDb::getEmployee( “Leha” );

Singleton vs. Monostate Construction: Singleton has lazy construction Don’t pay unless you need it! Monostates are always constructed Singleton can have non-trivial constructors Monostates can’t have non-trivial constructors Destruction: Singleton destruction is not defined Monostate destructon is well-defined

Strategy Problem: - different employees are paid differently - what if we need to add hourly paid manager ? - hierarchy is hard to maintain

Solution PaymentPolicy specifies an algorithm for payment calculation

Strategy Pattern Also known as: Policy Benefits: - different strategies can be swapped in and out - context is closed to changes or additions of strategies

Bridge Problem: - Client code depends on platform - To support a new platform, we need to reproduce all Window’s derivatives

Solution All operations on Window subclasses are implemented in terms of abstract operations from the WindowImp interface Makes Window and its subclasses platform-independent Q: How to make clients independent on WindowImp subclasses? Window drawText() WindowImp drawText() 11 XWindowImp drawText() PMWindowImp drawText() DialogWindowIconWindow Bridge

Bridge Pattern Also known as: Handle/Body Benefits: - Eliminates DIP & OCP violation - Increases maintainability

Proxy Problem: We need to optimize object access in order to make resource allocation operations on demand

Solution Solution: - use a surrogate that will initiate create operation on demand - clients can treat RealImage and ImageProxy as similar objects.

Proxy Pattern Also known as: Surrogate Applicability: - remote proxy - virtual proxy (creation of real object on demand) - protection proxy (for example: ACL support)

Abstract Factory Problem: - creating objects creates a dependency on a concrete type - all other manipulations are done through interface !

Solution Make a class whose responsibility is to make objects Making objects can’t be avoided, but can be contained

Factory Pattern Isolates concrete classes, makes Types family changes easier

Stairway to Heaven Problem: - We wish to make an hierarchy of classes persistent, but we don’t want to depend upon the vendor of our database

Solution Use Adaptor pattern at each level in the hierarchy  Requires virtual multiple inheritance Knowledge of persistence Knowledge of business

Visitor What if we need to configure modems differently for different operating systems?

Visitor Problem? ISP violation. Hard to support new OSes.

Solution

Issues Problem? A cycle involving modem implementations. Hard to support new modem types.

New Solution: Acyclic Visitor