In this Lecture you will Learn: Design Patterns. Patterns vs. Frameworks. Patterns vs. Frameworks

Similar documents
Object-Oriented Design

Design Pattern and Software Architecture: IV. Design Pattern

Presenter: Dong hyun Park

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

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

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

Chapter 8: Class and Method Design

Software Engineering - I An Introduction to Software Construction Techniques for Industrial Strength Software

Design Patterns. An introduction

Object-Oriented Design

Design Patterns. Gunnar Gotshalks A4-1

SDC Design patterns GoF

CHAPTER 9 DESIGN ENGINEERING. Overview

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

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

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

Coordination Patterns

Lethbridge/Laganière 2005 Chapter 9: Architecting and designing software 6

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

Lecture 13: Design Patterns

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Topics in Object-Oriented Design Patterns

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

Learning Objectives. C++ For Artists 2003 Rick Miller All Rights Reserved xli

10조 이호진 이지 호

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

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

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

Elementary Concepts of Object Class

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

In this Lecture you will Learn: System Design. System Architecture. System Architecture

Summary of the course lectures

Think of drawing/diagramming editors. ECE450 Software Engineering II. The problem. The Composite pattern

BCS Higher Education Qualifications. Diploma in IT. Object Oriented Programming Syllabus

Software Engineering Prof. Rushikesh K.Joshi IIT Bombay Lecture-15 Design Patterns

Lectures 24 and 25 Introduction to Architectural Styles and Design Patterns

In this Lecture you will Learn: Object Design. Information Sources for Object Design. Class Specification: Attributes

Object-Oriented Concepts and Design Principles

The Software Design Process. CSCE 315 Programming Studio, Fall 2017 Tanzir Ahmed

An Introduction to Patterns

EINDHOVEN UNIVERSITY OF TECHNOLOGY

CS/CE 2336 Computer Science II

INTERNAL ASSESSMENT TEST III Answer Schema

Object-Oriented Design

CSC207H: Software Design Lecture 6

MechEng SE3 Lecture 7 Domain Modelling

Chapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures

4.1 Introduction Programming preliminaries Constructors Destructors An example... 3

Plan. Design principles: laughing in the face of change. What kind of change? What are we trying to achieve?

Tuesday, October 4. Announcements

An Introduction to Patterns

DESIGN PATTERN - INTERVIEW QUESTIONS

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

Design Pattern: Composite

1 Software Architecture

OODP Session 4. Web Page: Visiting Hours: Tuesday 17:00 to 19:00

Object Orientated Analysis and Design. Benjamin Kenwright

Introduction to Design Patterns

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

CHAPTER 5 GENERAL OOP CONCEPTS

Introduction to Design Patterns

Plan. Design principles: laughing in the face of change. What kind of change? What are we trying to achieve?

WHAT IS SOFTWARE ARCHITECTURE?

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

Application Architectures, Design Patterns

Chapter 1: Programming Principles

Topic : Object Oriented Design Principles

L18.1 Introduction... 2

Chapter 5 Object-Oriented Programming

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

CS 247: Software Engineering Principles. Design Patterns

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107

Lecture Material. Design Patterns. Visitor Client-Server Factory Singleton

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

Object-Oriented Design

Design Patterns. Lecture 10: OOP, autumn 2003

What are patterns? Design Patterns. Design patterns. Creational patterns. The factory pattern. Factory pattern structure. Lecture 10: OOP, autumn 2003

Design Patterns Revisited

CPSC 310 Software Engineering. Lecture 11. Design Patterns

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

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

3 Product Management Anti-Patterns by Thomas Schranz

SOFTWARE PATTERNS. Joseph Bonello

Work groups meeting 3

COURSE 2 DESIGN PATTERNS

17. GRASP: Designing Objects with Responsibilities

Design Patterns. CSE870: Advanced Software Engineering (Design Patterns): Cheng

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

Design Patterns! Acknowledgements!

GOF Patterns Applied

VB.NET. Exercise 1: Creating Your First Application in Visual Basic.NET

Design Patterns. Paul Jackson. School of Informatics University of Edinburgh

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

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

Responsibilities. Using several specific design principles to guide OO design decisions.

What is a Pattern? Lecture 40: Design Patterns. Elements of Design Patterns. What are design patterns?

LABORATORY 1 REVISION

Recap : UML artefacts. Black Box Requirements. Functional Specification. System. System. Test. Design. System. System. Development.

Inheritance. EEC 521: Software Engineering. Dealing with Change. Polymorphism. Software Design. Changing requirements Code needs to be flexible

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

Transcription:

In this Lecture you will Learn: Design Patterns Chapter 15 What types of patterns have been identified in software development How to apply design patterns during software development The benefits and difficulties that may arise when using patterns M8748 Peter Lo 2007 1 M8748 Peter Lo 2007 2 Patterns vs. Frameworks Frameworks are partially completed software systems that may be targeted at a specified type of application. Frameworks is a reusable mini-architecture that provides structure and behaviour common to all applications of this type. Patterns vs. Frameworks Patterns are more abstract and general than frameworks Patterns cannot be directly implemented in a particular software environment Patterns are more primitive than frameworks M8748 Peter Lo 2007 3 M8748 Peter Lo 2007 4

Pattern Catalogues and Languages Pattern are group into Catalogues and Language: A Pattern Catalogue is a group of patterns that are related to some extent and may be used together or independently of each other The patterns in a Pattern Language are more closely related, and work together to solve problems in a specific domain Software Development Principles and Pattern Buschmann et al. (1996) suggest the key principles that underlie pattern. Abstraction Encapsulation Information Hiding Modularization Separation of Concerns Coupling and Cohesion Sufficiency Completeness and Primitiveness Separation of Policy and Implementation Separation of Interface and Implementation Single Point of Reference Divide and Conquer M8748 Peter Lo 2007 5 M8748 Peter Lo 2007 6 Patterns and Non-functional Requirements Buschmann et al. (1996) identify the most important non-functional properties of a software architecture Changeability Interoperability Efficiency Reliability Testability Reusability Documenting Pattern Pattern Template The Pattern Template determines the style and structure of the pattern description, and these vary in the emphasis they place on different aspects of pattern. The differences between pattern templates may mirror variations in the problem domain but there is no consensus as to the most appropriate template even within a particular problem domain. M8748 Peter Lo 2007 7 M8748 Peter Lo 2007 8

Template Content Other Aspects of Templates A pattern description should include the following elements: Name Meaningful that reflects the knowledge embodied by the pattern Problem Description of the problem that the pattern addresses (the intent of the pattern). Context Represents the circumstances or preconditions under which it can occur. Forces Embodied in a pattern are the constraints or issues that must be addressed by the solution Solution Description of the static and dynamic relationships among the components of the pattern A Pattern template may more extensive. Some other features that have figured in pattern template are: An example of the use of a pattern that serves as a guide to its application The context that results from the use of the pattern The rationale that justifies the chosen solution Related patterns Known uses of the pattern that validate it A list of aliases for the pattern Sample program code and implementation details M8748 Peter Lo 2007 9 M8748 Peter Lo 2007 10 Type of Design Patterns In the catalogue of 23 design patterns presented by Gamma et al. (1995) patterns are classified according to their scope and purpose. The 3 main categories of purpose that a pattern can have: Creational Structural Behavioural Type of Design Patterns Typically address issues concerning Changeability, and involve several different aspects: Maintainability Extensibility Restructuring Portability M8748 Peter Lo 2007 11 M8748 Peter Lo 2007 12

Creational Patterns Creational Patterns: Singleton Concerned with the construction of object instances Separate the operation of an application from how its objects are created Gives the designer considerable flexibility in configuring all aspects of object creation This configuration might be dynamic (at run-time) or static (at compile-time) Singleton can be used to ensure that only one instance of a class is created. The class constructor in the Singleton pattern is private so that it can only be accessed the class-scope instance() method. This ensures that the Singleton class has total control over its own instantiation General form of Singleton pattern M8748 Peter Lo 2007 13 M8748 Peter Lo 2007 14 Singleton Example How does one ensure that only one instance of the company class is created for following class? Singleton Example Solution Restrict access to the constructor The use of class-scope operations allows global access. M8748 Peter Lo 2007 15 M8748 Peter Lo 2007 16

Singleton Example Advantages of Singleton Different subclasses of Company can be instantiated as needed, depending on run-time circumstances It provide controlled access to the sole object instance as the Singleton class encapsulates the instance. The namespace is not unnecessarily extended with global variables. The Singleton class may be sub-classed. At system start-up user-selected options may determine which of the subclass is instantiated when the Singleton class is first accessed A variation of this pattern can be used to create a specified number of instances if required. M8748 Peter Lo 2007 17 M8748 Peter Lo 2007 18 Disadvantages of Singleton Structural Patterns Using the pattern introduces some additional message passing. To access the singleton instance the class scope method has to be accessed first rather than accessing the instance directly The pattern limits the flexibility of the application. If requirements change and as a result the singleton class may have many instances then accommodating this new requirement necessitates signature modification to the system. The singleton pattern is quite well known and developers are tempted to use it in circumstances that are inappropriate. Patterns must be used with care. Concerned with the way in which classes and objects are organized Offer effective ways of using object-oriented constructs such as inheritance, aggregation and composition to satisfy particular requirements M8748 Peter Lo 2007 19 M8748 Peter Lo 2007 20

Composite Pattern General Form Composite Example How can we present the same interface for a media clip whether it is composite or not? M8748 Peter Lo 2007 21 M8748 Peter Lo 2007 22 Composite Example Composite applied to Agate How can we incorporate composite structures? M8748 Peter Lo 2007 23 M8748 Peter Lo 2007 24

Behavioural Patterns Address the problems that arise when assigning responsibilities to classes and when designing algorithms Suggest particular static relationships between objects and classes and also describe how the objects communicate General form of State Pattern The State Pattern use both of these techniques: Use inheritance structures to spread behavior across the subclasses Use aggregation and composition to build complex behavior from simpler component M8748 Peter Lo 2007 25 M8748 Peter Lo 2007 26 State Example Consider the class Campaign. State Example State pattern applied to the class Campaign M8748 Peter Lo 2007 27 M8748 Peter Lo 2007 28

State Example Some State pattern objects for Agate note that there are 6 Campaign objects sharing the four State objects. Explanation of State Example It has four states Commissioned, Active, Completed and Paid A Campaign object has different behaviour depending upon which state it occupies Operations have case statements giving this alternative behaviour The class factored into separate components one for each of its states M8748 Peter Lo 2007 29 M8748 Peter Lo 2007 30 Implementation Problems of State Pattern The State pattern may have the following implementation problems. If State objects cannot be shared amongst Context objects (i.e. are not pure state objects) then each Context object will have to have its own State object thus increasing storage requirements. State objects may have to be created and deleted as the Context object changes state increasing the processing requirement. The use of the State pattern introduces one additional message, which also possibly increases the processing requirement. How to use Design Patterns? Before using a pattern to resolve the problem ask Is there a pattern that addresses a similar problem? Does the pattern trigger an alternative solution that may be more acceptable? Is there a simpler solution? Patterns should not be used just for the sake of it Is the context of the pattern consistent with that of the problem? Are the consequences of using the pattern acceptable? Are there constraints imposed by the software environment that would conflict with the use of the pattern? M8748 Peter Lo 2007 31 M8748 Peter Lo 2007 32

Effective Use of Patterns The 7 steps from Gamma et al. are as follows. Read the pattern to get a complete overview Study the Structure, Participants and Collaborations of the pattern in detail Examine the Sample Code to see an example of the pattern in use Choose names for the pattern s participants (i.e. classes) that are meaningful to the application Define the classes Choose application specific names for the operations Implement operations that perform the responsibilities and collaborations in the pattern M8748 Peter Lo 2007 33 Dangers and Benefits of the Use of Pattern Two general dangers of using patterns are the inappropriate application of a pattern and some limitation on creativity. Two advantages of using patterns are the introduction of a reuse culture at the design level and the rich source of development experience they offer. M8748 Peter Lo 2007 34