Design Patterns CMPS 2143. Design Patterns Consider previous solutions to problems similar to any new problem ▫ must have some characteristics in common.

Slides:



Advertisements
Similar presentations
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Advertisements

 Recent researches show that predicative programming can be used to specify OO concepts including classes, objects, interfaces, methods, single and multiple.
Design Patterns Introduction What is a Design Pattern? Why were they developed? Why should we use them? How important are they?
Design Patterns Section 7.1 (JIA’s) Section (till page 259) (JIA’s) Section 7.2.2(JIA’s) Section (JIA’s)
Object-Oriented Design Patterns Composite Singleton State Observer … Autumn 2012UCN Technology: IT/Computer Science1.
OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
March Ron McFadyen1 Design Patterns In software engineering, a design pattern is a generally repeatable solution to a commonly-occurring problem.
Plab – Tirgul 12 Design Patterns
Observer Pattern Fall 2005 OOPD John Anthony. What is a Pattern? “Each pattern describes a problem which occurs over and over again in our environment,
March Ron McFadyen1 Design Patterns In software engineering, a design pattern is a generally repeatable solution to a commonly-occurring problem.
Design Patterns Part IV (TIC++V2:C10) Yingcai Xiao 10/01/08.
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.
More OOP Design Patterns
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.
Singleton Christopher Chiaverini Software Design & Documentation September 18, 2003.
Design Patterns.
Chapter 4 Objects and Classes.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
1 COSC2767: Object-Oriented Programming Haibin Zhu, Ph. D. Professor of CS, Nipissing University.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
Copyright © 2002, Systems and Computer Engineering, Carleton University Patterns.ppt * Object-Oriented Software Development Part 11.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
Object-Oriented Design Principles and Patterns. © 2005, James R. Vallino2 How Do You Design? What principles guide you when you create a design? What.
Partitioning Patterns How to partition complex actors and concepts into multiple classes. Layered Initialization Filter Composite.
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.
CSE 432: Design Patterns Introduction What’s a Pattern? What’s an Idiom? According to Alexander, a pattern: –Describes a recurring problem –Describes the.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
CSC 480 Software Engineering Design With Patterns.
Simple Classes. ADTs A specification for a real world data item –defines types and valid ranges –defines valid operations on the data. Specification is.
Programmeerimine Delphi keskkonnas MTAT Programmeerimine Delphi keskkonnas MTAT Jelena Zaitseva
The Singleton Pattern SE-2811 Dr. Mark L. Hornick 1.
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)
CSE 332: Design Patterns Review: Design Pattern Structure A design pattern has a name –So when someone says “Adapter” you know what they mean –So you can.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Design Patterns Introduction
1 Chapter 5:Design Patterns. 2 What are design pattern?  Schematic description of design solution to recurring problems in software design and,  Reusable.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
CSC 480 Software Engineering Design With Patterns.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
The Decorator Pattern (Structural) ©SoftMoore ConsultingSlide 1.
Subclassing, pt. 2 Method overriding, virtual methods, abstract classes/methods COMP 401, Fall 2014 Lecture 9 9/16/2014.
Duke CPS Programming Heuristics l Identify the aspects of your application that vary and separate them from what stays the same ä Take what varies.
Class Relationships Lecture Oo08 Polymorphism. References n Booch, et al, The Unified Modeling Language User Guide, Chapt 10 p.125 n Fowler & Scott, UML.
1 Lecture Material Design Patterns Visitor Client-Server Factory Singleton.
Patterns in programming
Design Patterns: MORE Examples
Design Patterns: Brief Examples
Chapter 5:Design Patterns
Introduction to Design Patterns
The Singleton Pattern SE-2811 Dr. Mark L. Hornick.
Agenda Warmup AP Exam Review: Litvin A2
Advanced Programming Behnam Hatami Fall 2017.
Software Engineering Lecture 7 - Design Patterns
CSC 480 Software Engineering
Review: Design Pattern Structure
CS 350 – Software Design Singleton – Chapter 21
Introduction to Design Patterns
CSC 480 Software Engineering
Chapter 8, Design Patterns Introduction
CSC 480 Software Engineering
Presentation transcript:

Design Patterns CMPS 2143

Design Patterns Consider previous solutions to problems similar to any new problem ▫ must have some characteristics in common ▫ tweak the solution Very few really new problems Whole bunch of patterns are documented that you can use

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 solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice. Christopher Alexander Aid in discussing structures and relationships at a higher level of abstraction (viewed as a community of interacting agents)

Two Reasons to use design patterns Speeds process of finding a solution ▫ don’t reinvent the wheel Naming patterns gives programmers a common vocabulary or language to discuss design alternatives.

What patterns aren’t. Patterns are a generalized concept, an idea formed in succinct manner, yet expressible in many different ways. They aren’t: ▫ an exact solution ▫ the basis of a code catalog

Controlling Information Flow Many design patterns deal with how information flows between a client/server or consumer/producer boundary. client info server

Easy Example: Adapter Pattern An object in your community (client) needs a service and requires a specific interface Another object provides the service, but does not support the desired interface CREATE AN ADAPTER! ▫ speaks the language of the client, but doesn’t do the work itself, it gets the service to do it

Coded example Client wants a DataBox but wants the methods in Collection class MyCollection implements Collection{ public boolean isEmpty() {return data.count()== 0;} public int size () {return data.count();} public void addElement (Object e) {data.add(e);} public boolean containsElement (Object e) { return data.find(e) != null;} public Object findElement (Object e) { return data.find(e);} private DataBox data = new DataBox(); }

Describing Patterns Special format to describe patterns Use a narrative with these parts ▫ name ▫ synopsis ▫ forces (or requirements of pattern) ▫ solution (or rather the essence of a solution) ▫ counterforces (reasons not to use the pattern) ▫ related patterns

Describing the Adapter Pattern ▫ name: Adapter ▫ synopsis: Used to connect a client who needs a service described using one interface with a provider who implements the desired functionality but uses a different interface ▫ solution : implements the interface as specified by the client, but rather than performing the given operations, passes the work on to the service provider ▫ counterforces: adds one layer of indirection between the client and provider and also introduces another class

Singleton Pattern Not all patterns deal with client/server interactions In Singleton pattern the developer of a class wants to ensure there is never more than one instance of the class

Coded Example of Singleton Pattern class SingletonClass { public: static SingletonClass * oneAndOnly () {return theOne;} //other non-constructor methods here private: //constructor Singleton () { //theOne is initialized here } //the member data static SingletonClass * theOne; }

Decorator Pattern Decorator pattern deals with how new functionality can be attached to existing objects ▫ inheritance is one way to do this ▫ inheritance is static and heavyweigth ▫ inheritance does not permit values to change their behavior dynamically during execution A decorator wraps around an existing object and satisfies the same requirements ▫ delegates much of responsibility to original ▫ occasionally adds new functionality

Decorator Pattern

Coded Example of Decorator from Java class BufferedInputStream extends InputStream { public BuffererInputStream (InputStream s) {data =s;} //other methods here private InputStream data; } InputStream reads bytes from input device, such as file. BufferedInputStream is a subclass of InputStream, adding the ability to buffer input ▫ can reset to an earlier point and can reread values NOTE: BufferedInputStream is-an Input Stream AND has-an InputStream

Observer Pattern Addresses problem of how two objects can stay synchronized without having direct knowledge of each other

Observer Pattern The model – part that is doing the actual work The view – portion of the program charged with displaying the results Need an intermediary ▫ ObserverManager communicates with both the model and the observers ▫ ObserverManager maintains list of models and they notify it when they change ▫ Observers register with ObserverManager Also known as Publish-Suscribe and ModelViewController

Model-View-Controller

Study pg. 478: 1, 3, 5, 15