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

Similar documents
Design Patterns. An introduction

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

Design Patterns. Gunnar Gotshalks A4-1

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

Using Design Patterns in Java Application Development

SDC Design patterns GoF

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

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

CS/CE 2336 Computer Science II

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

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

Object-Oriented Design

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

Topics in Object-Oriented Design Patterns

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

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

ADAPTER. Topics. Presented By: Mallampati Bhava Chaitanya

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

Tuesday, October 4. Announcements

An Introduction to Patterns

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

An Introduction to Patterns

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

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

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

Coordination Patterns

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

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

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

Review Software Engineering October, 7, Adrian Iftene

DESIGN PATTERN - INTERVIEW QUESTIONS

Object Oriented Paradigm

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

Lectures 24 and 25 Introduction to Architectural Styles and Design Patterns

COSC 3351 Software Design. Design Patterns Structural Patterns (I)

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

Foundations of Software Engineering Design Patterns -- Introduction

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

Design Patterns Reid Holmes

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

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

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

INSTITUTE OF AERONAUTICAL ENGINEERING

Applying the Observer Design Pattern

Software Engineering I (02161)

Design patterns. Valentina Presutti courtesy of Paolo Ciancarini

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

Design Patterns IV Structural Design Patterns, 1

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

6.3 Patterns. Definition: Design Patterns

Object-Oriented Oriented Programming Adapter Pattern. CSIE Department, NTUT Woei-Kae Chen

Reuse at Design Level: Design Patterns

Design Patterns. GoF design patterns catalog

Application Architectures, Design Patterns

1 Software Architecture

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

A Reconnaissance on Design Patterns

Design Patterns IV. Alexei Khorev. 1 Structural Patterns. Structural Patterns. 2 Adapter Design Patterns IV. Alexei Khorev. Structural Patterns

A Rapid Overview of UML

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

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

2.1 Design Patterns and Architecture (continued)

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

Design Patterns! Acknowledgements!

Object-Oriented Oriented Programming Adapter Pattern

2.1 Design Patterns and Architecture (continued)

Applying the Decorator Design Pattern

CISC 322 Software Architecture

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

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

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

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

Design Patterns. CSC207 Fall 2017

Design Patterns. Definition of a Design Pattern

SOFTWARE ENGINEERING SOFTWARE DESIGN. Saulius Ragaišis.

UNIT I Introduction to Design Patterns

CS251 Software Engineering Lectures 18: Intro to DP

Lecture 20: Design Patterns II

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

Introduction and History

What is Design Patterns?

LECTURE NOTES ON DESIGN PATTERNS MCA III YEAR, V SEMESTER (JNTUA-R09)

APPLYING DESIGN PATTERNS TO SCA IMPLEMENTATIONS

Summary of the course lectures

Introduction to Software Engineering: Object Design I Reuse & Patterns

Design Patterns. CSC207 Winter 2017

Design pa*erns. Based on slides by Glenn D. Blank

Information systems modelling UML and service description languages

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

Lecture 13: Design Patterns

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

Programmazione. Prof. Marco Bertini

CSC7203 : Advanced Object Oriented Development. J Paul Gibson, D311. Design Patterns

Work groups meeting 3

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

Object-Oriented Oriented Programming

The GoF Design Patterns Reference

Information Systems Analysis and Design. XIV. Design Patterns. Design Patterns 1

Design patterns. Jef De Smedt Beta VZW

CPSC 310 Software Engineering. Lecture 11. Design Patterns

Transcription:

Idioms and Design Patterns Martin Skogevall IDE, Mälardalen University 2005-04-07

Acronyms Object Oriented Analysis and Design (OOAD) Object Oriented Programming (OOD Software Design Patterns (SDP) Gang of Four (GoF) Graphical User Interface (GUI) Object Oriented Languages (OOL)

Idioms Idioms exist in most languages Often cultural expressions Usually catches machine translators off-guard Examples It's raining cats and dogs while(*p) {*p++ = *q++;}

Abstract Idioms Immutable interfaces in Java Java lacks the const -specifier for declaring nonmodifiable variables (immutable variables) One standard solution is to expose interfaces that only allows non-mutating operations

Idioms Idioms in a language can help expressing complex subtexts with simpler constructs Other people understand what you are trying to accomplish or describe when they recognize the idiom Documenting idioms can thus help in understanding expressions of code or speech The idea behind a certain idiom can transcend languages, but they are realized differently

Software Design Patterns Language independent descriptions of design solutions A tested and well-known solution to a recurring design problem

Software Design Patterns Intent Capture design experiences from experts Reuse successful solutions to standard problems Bridge between OOAD and OOP

Software Design Patterns Expected results High degree of reuse Elegant systems Well tested solutions Flexibility

Software Design Patterns Solution Abstractions... Description of the problem in natural language Solution to the problem in natural language with the help of e.g. UML Design Pattern Catalogues and Pattern Languages

Why bother with DP? Excellent OOD requires experience Knowing OOD-methods by hand does not guarantee a good design OOD-methods usually concentrate on notation Will often just make for a good specification DP gives a common vocabulary when describing design decisions Easier communication Faster understanding of complex systems

History Christopher Alexander The Timeless Way of Building, (1979) A Pattern Language, (1977) SDP OOPSLA Using Pattern Languages for Object- Oriented Programs, (1987) GoF Design Patterns, (1995)

The Gang of Four Design Patterns Elements of Reusable Object- Oriented Software Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides 1998 GoF received DrDobb Journal's Excellence in Programming Awards SDP bible

What is a Design Pattern? A description of communicating classes and/or objects which have been composed to give a generic solution to a recurring problem Describes a solution to a recurring design problem Description of how classes interact to accomplish the task Design Patterns have a relatively high level of abstraction Is a generic solution

Studying Design Patterns Studying DP is an effective way to learn OOD Learn from experts' knowledge DP is still more art than science To take full advantage of DP you need Prior experience of OO Creativity

The Design Pattern Structure Name A good name that reflects the design pattern's functionality is very important Not too specialized The problem The solution Consequences

Example Model-View-Controller Name Model-View-Controller (MVC) The Problem Disconnect dependencies between logic and data to be displayed from the code that displays the data. Also disconnect handling of user input from the data model. The Solution MVC utilizes other DPs to achieve it's goal

MVC Model user input Control View visual output A view reflects the state in the model The model does not know the view Why?

MVC The View How can the model notify the views when data is changed and still be unaware of the views? Some kind of message dispatcher is needed Fortunately, there is a design pattern that fits perfectly View 1 Model? View 2 View 3

MVC The View The Observer Pattern Define a one-to-many dependency between objects so that when one object changes state, all its depentents are notified and updated automatically Decreases coupling between the model classes and the view classes

MVC The Controller The controller handles user input and translates that into operations on the model This makes it possible to change translations of user input without modifying the model The relation between the model and controller is where another design pattern can be used

MVC The Controller The Strategy Pattern Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it Allows even for changes of translations during run-time E.g. a sportscar simulator can either accept steering input from a joystick or from the keyboard

MVC Wrap-up The Model-View-Controller is a domain specific design pattern It is used in GUI applications The MVC is built on other domain independent design patterns Observer and Strategy Helps us achieving even more fundamental design patterns Coupling and Cohesion

Common Errors in Designs Objects are created by explicit naming Example Button *b = new MotifButton; Problem The class describes a certain implementation Solution Create instances indirectly Abstract Factory, Factory Method, Prototype

Common Errors in Designs Dependencies on specific operations Problem The target of a message is hard-coded Solution Make it possible to delegate the message Chain of Responsibility, Command

Common Errors in Designs Hardware/software dependencies Problem The system becomes hart to port to other platforms Solution Design platform independent code Abstract Factory, Bridge

Common Errors in Designs Dependencies on object representation and implementation Problem Clients knows how an object is represented Solution Hide the information from clients Abstract Factory, Bridge, Memento, Proxy

Common Errors in Designs Too strong coupling between classes/objects Problem Hard to change and reuse these classes Solution Use patterns that gives loose couplings Abstract Factory, Bridge, Chain of Responsibility, Command, Facade, Mediator, Observer

Common Errors in Designs Algorithm dependencies Problem Algorithms can often change Solution Isolate the algorithms in their own objects Builder, Iterator, Strategy, Template Method, Visitor

Common Errors in Designs Extend functionality through inheritance Problem Requires intimate knowledge of the superclasses Solution Prefer composition or delegation Bridge, Chain of Responsibility, Composite, Decorator, Observer, Strategy

Common Errors in Designs Inability to change class interface and implementation (due to third party vendors, or legacy) Problem Source code cannot be changed Solution Some design patterns allow certain modifications Adapter, Decorator, Visitor

Design Pattern Classification GoF classified design patterns into three categories Creational Structural Behavioral

A Design Pattern Template Name and Classification Intent Also Known As Motivation Applicability Structure Collaborations Consequences Implementation Sample Code Known Uses Related Patterns Participants

Case Study The Adapter Pattern Intent To convert a class' interface so that incompatible classes can cooperate A.k.a Wrapper Example Graphics Editor Basic classes: line, circle, polygon and text Abstraction: Graphical objects can draw themselves and be manipulated by the user

Editor Design Editor Shape BoundingBox() CreateManipulator() TextView Circle BoundingBox() CreateManipulator() Text BoundingBox() CreateManipulator() GetExtent() GetOrigin()

Editor Design How can the system provided TextView class be reused by the graphical editor? Consider two solutions Class version of Adapter Object version of Adapter

Class Adapter Client Target Request() Adaptee SpecificRequest() Adapter Request() SpecificRequest()

Object Adapter Client Target Request() Adaptee SpecificRequest() adaptee Adapter Request() adaptee->specificrequest()

Adapter - Consequences Class Adapter Can only access functionality from one adaptee class Methods are hard to shadow Introduces only one object No extra call-overhead Object Adapter Can access functionality from a whole class hierarchy Methods can easily be shadowed Needs more manual labor to create

Adapter Related Patterns Bridge Decorator Proxy These will be presented on Monday

Design Patterns Requirements No special tools needed A compiler for a OOL E.g. Java, C++, Ada 95, Smalltalk Features needed except for classes and objects Inheritance Polymorphism It is easier if the compiler supports these

Design Pattern Drawbacks When should DP not be used? The flexibility introduced often relies on an extra level of indirection Complicates design More overhead Study the section Consequences in the DP description to understand the common drawbacks of a certain DP

Conclusion Software Design Patterns gives Effective design Increased understanding Common vocabulary Stable systems Better reuse Automation

Pattern Libraries A lot of design patterns are utilized in different frameworks These DP are also usually domain specific Loki is a C++ library with implemented design patterns Alexei Alexandrescu, Modern C++ design Relies heavily on templates Only recently compilers are able to digest the library

Observer Define a one-to-many dependency between objects so that when one object changes state, all its depentents are notified and updated automatically

Strategy Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it

Command Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations