Object Oriented Methods with UML. Introduction to Design Patterns- Lecture 8

Similar documents
Design Patterns. An introduction

DESIGN PATTERN - INTERVIEW QUESTIONS

Design Patterns. Manuel Mastrofini. Systems Engineering and Web Services. University of Rome Tor Vergata June 2011

Using Design Patterns in Java Application Development

Ingegneria del Software Corso di Laurea in Informatica per il Management. Design Patterns part 1

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Design Pattern. CMPSC 487 Lecture 10 Topics: Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, et al.)

Design Patterns. Dr. Rania Khairy. Software Engineering and Development Tool

Tuesday, October 4. Announcements

Design Patterns. Observations. Electrical Engineering Patterns. Mechanical Engineering Patterns

Object-oriented Software Design Patterns

An Introduction to Patterns

EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 6: Design Patterns

be used for more than one use case (for instance, for use cases Create User and Delete User, one can have one UserController, instead of two separate

Ingegneria del Software Corso di Laurea in Informatica per il Management. Design Patterns part 1

Applying the Observer Design Pattern

Idioms and Design Patterns. Martin Skogevall IDE, Mälardalen University

What is Design Patterns?

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Object-Oriented Design

SDC Design patterns GoF

MVC. Model-View-Controller. Design Patterns. Certain programs reuse the same basic structure or set of ideas

Applying the Decorator Design Pattern

An Introduction to Patterns

A Rapid Overview of UML

Applying Some Gang of Four Design Patterns CSSE 574: Session 5, Part 3

Trusted Components. Reuse, Contracts and Patterns. Prof. Dr. Bertrand Meyer Dr. Karine Arnout

Design Patterns. Hausi A. Müller University of Victoria. Software Architecture Course Spring 2000

1 Software Architecture

Introduction to Software Engineering: Object Design I Reuse & Patterns

Lectures 24 and 25 Introduction to Architectural Styles and Design Patterns

The Strategy Pattern Design Principle: Design Principle: Design Principle:

Application Architectures, Design Patterns

CHAPTER 6: CREATIONAL DESIGN PATTERNS

Applying Design Patterns to SCA Implementations

Review Software Engineering October, 7, Adrian Iftene

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

Object Oriented Paradigm

The GoF Design Patterns Reference

A Reconnaissance on Design Patterns

Topics in Object-Oriented Design Patterns

APPLYING DESIGN PATTERNS TO SCA IMPLEMENTATIONS

Design Patterns. SE3A04 Tutorial. Jason Jaskolka

CS251 Software Engineering Lectures 18: Intro to DP

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

Applying the Factory Method Design Pattern

Software Design COSC 4353/6353 D R. R A J S I N G H

UNIT I Introduction to Design Patterns

A Primer on Design Patterns

What is Design Patterns?

2.1 Design Patterns and Architecture (continued)

Design Patterns. "Gang of Four"* Design Patterns. "Gang of Four" Design Patterns. Design Pattern. CS 247: Software Engineering Principles

2.1 Design Patterns and Architecture (continued)

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D.

CS 247: Software Engineering Principles. Design Patterns

Patterns. Erich Gamma Richard Helm Ralph Johnson John Vlissides

Socket attaches to a Ratchet. 2) Bridge Decouple an abstraction from its implementation so that the two can vary independently.

TDDB84. Lecture 2. fredag 6 september 13

Lecture 13: Design Patterns

Pattern Resources. Lecture 25: Design Patterns. What are Patterns? Design Patterns. Pattern Languages of Programming. The Portland Pattern Repository

Lecture 4: Observer Pattern, Event Library and Componentization

CS/CE 2336 Computer Science II

Design Patterns: Structural and Behavioural

Design patterns. OOD Lecture 6

Information systems modelling UML and service description languages

Design patterns generic models

Applying Design Patterns to accelerate development of reusable, configurable and portable UVCs. Accellera Systems Initiative 1

Goals of Lecture. Lecture 27: OO Design Patterns. Pattern Resources. Design Patterns. Cover OO Design Patterns. Pattern Languages of Programming

Software Reengineering Refactoring To Patterns. Martin Pinzger Delft University of Technology

Facade and Adapter. Comp-303 : Programming Techniques Lecture 19. Alexandre Denault Computer Science McGill University Winter 2004

CPSC 310 Software Engineering. Lecture 11. Design Patterns

Nat. Thomas Software Engineering Telephonics Inc. Long Island IEEE Lecture Series

CSCI Object Oriented Design: Frameworks and Design Patterns George Blankenship. Frameworks and Design George Blankenship 1

Design Patterns. Gunnar Gotshalks A4-1

The Design Patterns Matrix From Analysis to Implementation

Software Engineering I (02161)

Lecture 20: Design Patterns II

Object-Oriented Design

Introduction and History

Extensibility Design Patterns From The Initial Stage of Application Life-Cycle

Design patterns. Jef De Smedt Beta VZW

What is Design Patterns?

UP Requirements. Software Design - Dr Eitan Hadar (c) Activities of greater emphasis in this book. UP Workflows. Business Modeling.

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

SYLLABUS CHAPTER - 1 [SOFTWARE REUSE SUCCESS FACTORS] Reuse Driven Software Engineering is a Business

Design Patterns Revisited

Software Development Project. Kazi Masudul Alam

SOFTWARE ENGINEERING SOFTWARE DESIGN. Saulius Ragaišis.

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1

Keywords: Abstract Factory, Singleton, Factory Method, Prototype, Builder, Composite, Flyweight, Decorator.

CSCI 253. Overview. The Elements of a Design Pattern. George Blankenship 1. Object Oriented Design: Iterator Pattern George Blankenship

CS 349 / SE 382 Design Patterns. Professor Michael Terry January 21, 2009

UNIT I Introduction to Design Patterns

administrivia today UML start design patterns Tuesday, September 28, 2010

Design Pa*erns. + Anima/on Undo/Redo Graphics and Hints

Overview of Patterns: Introduction

Ownership in Design Patterns. Master's Thesis Final Presentation Stefan Nägeli

Slide 1. Design Patterns. Prof. Mirco Tribastone, Ph.D

WS01/02 - Design Pattern and Software Architecture

A few important patterns and their connections

Transcription:

Object Oriented Methods with UML Introduction to Design Patterns- Lecture 8

Topics(03/05/16) Design Patterns

Design Pattern In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. It is a description or template for how to solve a problem that can be used in many different situations.

What is Gang-of-Four DP? In 1994, four authors Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides published a book titled Design Patterns - Elements of Reusable Object-Oriented Software which initiated the concept of Design Pattern in Software development. These authors are collectively known as Gang of Four (GOF). According to these authors design patterns are primarily based on the following principles of object orientated design. Program to an interface not an implementation Favor object composition over inheritance

Issues in Software Design Concurrency: How to decompose the system into processes,tasks and threads. Controlling and Handling of Events How to organize the flow of data to control temporal events Distribution How the objects communicate with each other. Interactive systems Which approach is used to interact with the users. Persistence How to handle the persistent data.

Types of Design Patterns S. N. Pattern & Description 1 Creational Patterns These design patterns provide a way to create objects while hiding the creation logic, rather than instantiating objects directly using new opreator. This gives program more flexibility in deciding which objects need to be created for a given use case. 2 Structural Patterns These design patterns concern class and object composition. Concept of inheritance is used to compose interfaces and define ways to compose objects to obtain new functionalities. 3 Behavioral Patterns These design patterns are specifically concerned with communication between objects. 4 J2EE Patterns These design patterns are specifically concerned with the presentation tier. These patterns are identified by Sun Java Center.

Creational patterns Abstract Factory Builder Factory Method Object Pool Prototype Singleton

Structural patterns Adapter Bridge Composite Decorator Facade Flyweight Private Class Data Proxy

Behavioral patterns Chain of Responsibility Command Interpreter Iterator Mediator Memento Null Object Observer State Strategy Template Method Visitor

Creational Pattern-Singleton Problem: Application needs one, and only one, instance of an object. Additionally, lazy initialization and global access are necessary.

Discussion Make the class of the single instance object responsible for creation, initialization, access, and enforcement. Declare the instance as a private static data member. Provide a public static member function that encapsulates all initialization code, and provides access to the instance.

Singleton pattern Solution :Singleton pattern

Singleton pattern

Check list-singleton pattern Define a private static attribute in the "single instance" class. Define a public static accessor function in the class. Do "lazy initialization" (creation on first use) in the accessor function. Define all constructors to be protected or private. Clients may only use the accessor function to manipulate the Singleton.

Sample Code-Singleton Implementation -Singleton

Structural pattern-adapter Problem An "off the shelf" component offers compelling functionality that you would like to reuse, but its "view of the world" is not compatible with the philosophy and architecture of the system currently being developed.

Discussion Adapter is about creating an intermediary abstraction that translates, or maps, the old component to the new system. Clients call methods on the Adapter object which redirects them into calls to the legacy component. This strategy can be implemented either with inheritance or with aggregation.

Discussion

Discussion The Adapter could also be thought of as a "wrapper". Class description: AbstractPlug : Abstract Target class Plug : Concrete Target class AbstractSwitchBoard : Abstract Adaptee class SwitchBoard : Concrete Adaptee class Adapter : Adapter class

Check list-adapter Pattern Identify the players: the component(s) that want to be accommodated (i.e. the client), and the component that needs to adapt (i.e. the adaptee). Identify the interface that the client requires. Design a "wrapper" class that can "impedance match" the adaptee to the client. The adapter/wrapper class "has a" instance of the adaptee class. The adapter/wrapper class "maps" the client interface to the adaptee interface. The client uses (is coupled to) the new interface

AbstractPlug Code class AbstractPlug { public: void virtual RoundPin(){ } void virtual PinCount(){ } };

// Concrete Target class Plug : public AbstractPlug { public: void RoundPin() { cout << " I am Round Pin" << endl; } void PinCount() { cout << " I have two pins" << endl; } };

// Abstract Adaptee // Abstract Adaptee class AbstractSwitchBoard { public: void virtual FlatPin() {} void virtual PinCount() {} }

// Concrete Adaptee class SwitchBoard : public AbstractSwitchBoard { public: void FlatPin() { cout << " Flat Pin" << endl; } void PinCount() { cout << " I have three pins" << endl; } };

// Adapter class Adapter : public AbstractPlug { public: AbstractSwitchBoard *T; Adapter(AbstractSwitchBoard *TT) { T = TT; } void RoundPin() { T->FlatPin(); } void PinCount() { T->PinCount(); } };

// Client code void _tmain(int argc, _TCHAR* argv[]) { SwitchBoard *myswitchboard = new SwitchBoard; AbstractPlug *adapter = new Adapter(mySwitchBoard); adapter->roundpin(); adapter->pincount(); }

References https://sourcemaking.com/design_patterns/