DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

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.
Matt Klein. Decorator Pattern  Intent  Attach Additional responsibilities to an object by dynamically. Decorators provide a flexible alternative to.
Let’s hear it for BUILDER!!!!!!!. Builder – The Intent \ Description To separate the construction of a complex object from its representation so that.
DESIGN PATTERNS OZGUR RAHMI DONMEZ.
Patterns Reusable solutions to common object-oriented programming problems When given a programming problem, re-use an existing solution. Gang of Four.
. Plab – Tirgul 12 Design Patterns. Design Patterns u The De-Facto Book on Design Patterns:
5/08 What is a Design Pattern „Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the.
IEG3080 Tutorial 7 Prepared by Ryan.
Design Pattern Course Builder Pattern 1 Mahdieh Monzavi AmirKabir University of Technology, Department of Computer Engineering & Information Technology.
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 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 ( ) ( ) ( )
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VI Composite, Iterator, and Visitor 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.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Design Patterns.
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.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
 How are you going to collaborate?  How are you going to divide up work?  How are you going to make sure that changes work with other people’s code?
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Object Oriented Software Engineering Chapter 16 and 17 review 2014/06/03.
GoF: Document Editor Example Rebecca Miller-Webster.
Structural Design Patterns
ECE450S – Software Engineering II
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Creational Patterns
DESIGN PATTERNS Sanjeeb Kumar Nanda 30-Aug What is a pattern? Pattern is a recurring solution to a standard problem Each Pattern describes a problem.
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.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
CS 210 Final Review November 28, CS 210 Adapter Pattern.
Design Patterns Introduction
Design Patterns SE464 Derek Rayside images from NetObjectives.com & Wikipedia.
Java Design Patterns Java Design Patterns. What are design patterns? the best solution for a recurring problem a technique for making code more flexible.
Example to motivate discussion We have two lists (of menu items) one implemented using ArrayList and another using Arrays. How does one work with these.
Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it by creating a representative object.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Reference – Object Oriented Software Development Using Java - Jia COP 3331 Object Oriented Analysis and Design Chapter 10 – Patterns Jean Muhammad.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
Overview of Creational Patterns ©SoftMoore ConsultingSlide 1.
PROTOTYPE. Design Pattern Space Purpose ScopeCreationalStructuralBehavioral ClassFactory MethodAdapterInterpreter Template Method ObjectAbstract factory.
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 CSCE 315 – Programming Studio Spring 2013.
Design Patterns: MORE Examples
Design Patterns: Brief Examples
Chapter 10 Design Patterns.
Software Design Patterns
MPCS – Advanced java Programming
Design Patterns Lecture part 2.
Factory Patterns 1.
Introduction to Design Patterns
Chapter 8, Design Patterns Builder
object oriented Principles of software design
Advanced Programming Behnam Hatami Fall 2017.
Software Engineering Lecture 7 - Design Patterns
Informatics 122 Software Design II
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Creational Patterns.
Informatics 122 Software Design II
Presentation transcript:

DESIGN PATTERNS COMMONLY USED PATTERNS

What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development environment. A pattern addresses a recurring design problem that arises in a specific design situation and presents a solution to it.

Types Of Design Patterns  The Gang Of Four Design Patterns  The EJB Design Patterns  The Sun J2EE Design patterns  The Application Design patterns

Elements of a Design Pattern Name Problem Solution Consequences

Classification Creational Patterns – are ones that create objects for you,rather than having you instantiate objects directly Structural Patterns – help you compose groups of objects into larger structures. Behavioral Patterns – help you define the communication between objects in your system and how the flow is controlled in a complex program.

GoF Design Patterns

Key Rules 1. Program to an interface and not to an implementation 2. Favor Object Composition over Inheritance.

Creational Patterns Factory Abstract Factory Builder Prototype Singleton

Factory Returns an instance of one of several possible classes depending on the data provided to it. Usually all of the classes it returns have a common parent class and common methods, but each of them performs a task differently and is optimized for different kinds of data.

Abstract Factory Abstraction over the Factory Design Pattern Abstract factory is the factory that returns one of several factories. One of the example to this could be a look-and-feel in Java.

UML Diagram

Pros & Cons ProsCons 1. Shields clients from concrete classes. 2. Easy to switch product family at runtime – just change concrete factory 3. “keep it in the family” – enforces product family grouping 1. Adding a new product means changing factory interface + all concrete factories

Builder Separates the construction process of a complex object from its representation. Used when the construction process is same but the representations may differ.

UML Diagram

Example -- UML RTFReader ParseRTF() while(t=get the next token){ switch t.Type{ CHAR: builder->ConvertCharacter(t.Char) FONT: builder->ConventFontCharnge(t.Font) PARA: Builder->ConventParagraph() } } TextConverter ConvertCharacter(char) ConvertFontChange(Font) ConvertParagraph() ASCIIConverter ConvertCharacter(char) GetASCIIText() TextConverter ConvertCharacter(char) ConvertFontChange(Font) ConvertParagraph() GetTeXText() TextWidgestConverter ConvertCharacter(char) ConvertFontChange(Font) ConvertParagraph() GetTextWidget() ASCIIText TeXText TextWidget builders

How is it different from Abstract Factory ? BuilderAbstract Factory It focuses on constructing a complex object step-by- step Returns a complex object as a final result AF emphasizes on creating a family of related objects Product gets returned immediately.

Prototype Used when creation of an object is time consuming or very complex. In java you can use this by implementing Cloneable interface. Pros.Cons. 1. Shields clients from concrete classes 2. The object is the factory - i.e. Product and Creator combined (saves coding a Creator for every Product) 3. Pre-configured object instances – instead of create/set member every time. 1. Requires Memory to hold prototype. 2. Clone() is hard to Implement. 3. Many prototypes must be passed.

Singleton Ensure a class has only one instance and provide a global point of access to it.

Structural Patterns Describes how classes and objects can be combined to make larger structures. Class Patterns – Inheritance Object Patterns – Composition

Structural Patterns Adapter Bridge Composite Façade Proxy Flyweight Decorator

Adaptor Pattern Converting an interface into another interface that its client is expected to see. Two flavor of this pattern come as: Class Adaptor Object Adaptor Java Adaptors

Class Adaptor

Object Adaptor

Bridge Pattern Separates Interface from its implementation so that both can be changed independently.

UML Diagram

Composite Pattern Allows clients to treat both single components and collection of components identically. Represents recursive data structures. Compose objects into tree structures to represent part-whole hierarchies.

UML Diagram

Façade Pattern Defines a high level interface that makes a sub system easier to use. Does not prevent an advanced user to use low level functionality. J2EE – Session Façade & Message Façade

UML Diagram

Proxy Provide a surrogate or placeholder for another object to control access to it. Provides identical interface as the original object has. Controls access to the original object and may be responsible for creating & destroying it

UML Diagram

Decorator Adding responsibilities to objects dynamically and without having to create a new class. Also known as “Wrapper” Used when sub-classing is impractical. Java I/O Streams is a good example.

UML Diagram

Flyweight Use sharing to support large numbers of fine-grained objects efficiently. Reusability of existing objects. Flyweight objects have two states intrinsic state & extrinsic state, that make them reusable.

UML Diagram

Example public class StringTest { public static void main(String[] args) { String fly = "fly", weight = "weight"; String fly2 = "fly", weight2 = "weight"; System.out.println(fly == fly2); System.out.println(weight == weight2); String distinctString = fly + weight; System.out.println(distinctString == "flyweight"); String flyweight = (fly + weight).intern(); System.out.println(flyweight == distinctString ); } } // TRUE // FALSE // TRUE

Strategy Pattern an object and its behavior are separated and put into two different classes. Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

UML Diagram

Thank You !