Software Engineering Lecture 7 - Design Patterns

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

18-1 Verifying Object Behavior and Collaboration Role playing – the act of simulating object behavior and collaboration by acting out an object’s behaviors.
Plab – Tirgul 12 Design Patterns
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:
IEG3080 Tutorial 7 Prepared by Ryan.
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 William A. Hoffman NYU OOP Class.
DESIGN PATTERNS Redesigning Applications And
Dept. of Computer Engineering, Amir-Kabir University 1 Design Patterns Dr. Noorhosseini Lecture 2.
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.
Design Patterns academy.zariba.com 1. Lecture Content 1.What are Design Patterns? 2.Creational 3.Structural 4.Behavioral 5.Architectural 6.Design Patterns.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Design Patterns Standardized Recurring model Fits in many location Opposite of customization Fundamental types of pattern Choose and use as desired and.
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.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
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.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
ECE450S – Software Engineering II
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
CDP-1 9. Creational Pattern. CDP-2 Creational Patterns Abstracts instantiation process Makes system independent of how its objects are –created –composed.
Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared.
Creational Patterns
CSC 480 Software Engineering Design With Patterns.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
FACTORY METHOD. Design Pattern Space Purpose ScopeCreationalStructuralBehavioral ClassFactory MethodAdapterInterpreter Template Method ObjectAbstract.
CS616: Software Engineering Spring 2009 Design Patterns Sami Taha.
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
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.
Advanced Object-oriented Design Patterns Creational Design Patterns.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
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.
Abstract Factory pattern Intent Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns: MORE Examples
The Object-Oriented Thought Process Chapter 15
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
Software Design Patterns
Design Pattern Catalogues
MPCS – Advanced java Programming
Introduction to Design Patterns
Design Patterns Lecture part 2.
Factory Patterns 1.
Design Patterns Lecture 1
Introduction to Design Patterns
Design Patterns with C# (and Food!)
object oriented Principles of software design
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
Design Patterns - A few examples
Informatics 122 Software Design II
CSC 480 Software Engineering
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
DESIGN PATTERNS : Introduction
Informatics 122 Software Design II
CSC 480 Software Engineering
Chapter 8, Design Patterns Introduction
Chapter 8, DesignPatterns Facade
Presentation transcript:

Software Engineering Lecture 7 - Design Patterns

Agenda Short introduction to the assignment Small introduction to important terms What is a design pattern and why use them? Presentation of a few patterns Singleton Factory Method Abstract Factory

About the assignment Goal Task Learn about different patterns Learn how to apply patterns Task Read about the patterns Identify 3 patterns that are used in your project Describe how they are implemented

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, NY 1977 He was an architect and said this about building patterns but it’s every bit as true about design patterns.

Why use design patterns? ”One way to measure the quality of an object-oriented system is to judge whether or not its developers have paid careful attention to the common collaborations among its objects. Focusing on such mechanisms during a system’s development yields an architecture that is smaller, simpler, and far more understandable than if these patterns are ignored.” -- Grady Booch Collaborations, structure, creations…

Why use design patterns? cont. Why use design patterns? Proven Reusable Expressive “Software entities should be open for extension but closed for modification” ”Program to an interface not an implementation” ”Favour composition over inheritance”

Four kinds of patterns Creational – Abstract Factory, Builder, Factory Method, Prototype, Singleton Structural – Adapter, Bridge, Composite, Decorator, Façade, Flyweight, Proxy Behavioral – Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor Software Architectural Patterns

Scenario

Alipes A platform encapsulating several different positioning-techniques One simple interface for all different techniques Keeps device specific implementation away from application developers

Singleton

Singleton -- problem Ensure only one instance of a class Defining everything static is a bad idea Not flexible Not encapsulated

Singleton -- solution Let a static method return itself Create if non-existing Singleton ensures only one instance Only requires one static method

Singleton -- UML Singleton Return uniqueInstance Underlined means static + Instance() : Singleton + SingletonOperation() + GetSingletonData() : singletonData + uniqueInstance singletonData

Singleton -- example Alipes example A server opens a port on the network Listens for commands on the opened port Can only have one instance of the server Use singleton

Singleton – example cont. 01. public Singleton { 02. // private instance 03. private static Singleton uniqueInstance; 04. 05. // private constructor 06. private Singleton() { 07. } 08. 09. // instantiation method 10. public static Singleton Instance() { 11. if (uniqueInstance == null) 12. uniqueInstance = new Singleton(); 13. return uniqueInstance; 14. } 15. ....

Singleton -- usage Consequences Controlled access to a sole entity Encapsulation Reduced name-space No global variables needed More flexible than class operations easier to change

Factory Method

Factory Method -- problem Create and maintain several components The class can’t anticipate the class of objects it must create Hardcoding which components to use is a bad idea Requires constant changing Not using a common interface is bad Makes the code hard to read

Factory method -- solution Define a common interface for the components Let subclasses decide which to instantiate Factory Method defers instantiation to subclasses

Factory Method -- UML Product Creator ConcreteProduct ConcreteCreator + FactoryMethod() : Product + AnOperation() ConcreteProduct ConcreteCreator + FactoryMethod() : ConcreteProduct

Factory Method - example Alipes example Several positining-tecniques Available positining services vary between devices Factory Method Create a common interface (PushPositionDevice) Implement support for a positioning-technique, implement the PushPositionDevice interface Let the factory instantiate the necessary positioning-devices

Factory Method – example cont. 01. public interface PushPositionDevice extends PositionDevice { 02. public void addPositionListener(PositionListener pl); 03. } 04. 05. public class DeviceManager implements PositionListener { 06. synchronized void loadAllDevices() { 07. String[] deviceClasses = getDevices(); 08. 09. for (int i=0; i < deviceClasses.length; i++) { 10. try { 11. Class c = Class.forName(deviceClasses[i]); 12. // open up the device 13. PushPositionDevice pd = (PushPositionDevice) c.newInstance(); 14. } 15. } catch (Exception err) { 16. } 17. // …} // …}

Factory method -- usage Consequences Makes dynamic architectures possible

Abstract Factory

Abstract Factory - Problem Ex: You want to be able to easily change the look-and-feel of your user interface (not hard coding it) Bad solution – Instantiating with concrete classes throughout the application: UnixWindow w = new UnixWindow();

Abstract Factory - Solution +CreateA(): AbstractA +CreateB(): AbstractB ConcreteFactory1 +CreateA(): A +CreateB(): B ConcreteFactory2 AbstractA A1 A2 AbstractB B1 B2 Client

Abstract Factory – Solution +CreateWindow(): AbstractWindow +CreateScrollbar(): AbstractScrollbar UnixFactory +CreateWindow(): UnixWindow +CreateScrollbar(): UnixScrollbar MacFactory +CreateWindow(): MacWindow +CreateScrollbar(): MacScrollbar AbstractWindow UnixWindow MacWindow AbstractScrollbar UnixScrollbar MacScrollbar Client

Abstract Factory - Applicability When a system should be independent of product creation, composition and representation configured with one of multiple families of products When a family of related product objects are designed to be used together When you want to provide a class library revealing only interfaces and not implementation

Abstract Factory - Consequences Isolates concrete classes Makes exchanging product families easy Promotes consistency among products Supporting new kinds of products is difficult

Thank you for listening, see you next time!