Overview of Patterns

Similar documents
Overview of Patterns: Introduction

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

Design Patterns Design patterns advantages:

Design Patterns. Gunnar Gotshalks A4-1

More on Design. CSCI 5828: Foundations of Software Engineering Lecture 23 Kenneth M. Anderson

A Case Study of Gang of Four (GoF) Patterns: Part 3

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

EMBEDDED SYSTEMS PROGRAMMING Design Patterns

Overview of Java Threads (Part 3)

Applying the Observer Design Pattern

A Case Study of Gang of Four (GoF) Patterns : Part 7

Using Design Patterns in Java Application Development

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

Foundations of Software Engineering Design Patterns -- Introduction

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

Android Services & Local IPC: The Command Processor Pattern (Part 1)

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

Integration With the Business Modeler

Outline. Design Patterns. Observer Pattern. Definitions & Classifications

EMBEDDED SYSTEMS PROGRAMMING Design Patterns

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

Studying software design patterns is an effective way to learn from the experience of others

Design Patterns. Definition of a Design Pattern

Overview of Java s Support for Polymorphism

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

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

The Java Executor (Part 1)

SDC Design patterns GoF

Topics in Object-Oriented Design Patterns

CS560. Lecture: Design Patterns II Includes slides by E. Gamma et al., 1995

Design Patterns. An introduction

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

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

THOMAS LATOZA SWE 621 FALL 2018 DESIGN PATTERNS

Overview of Frameworks: Part 3

Object Oriented Design and Programming Revision

Java Semaphore (Part 1)

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

Java Monitor Objects: Synchronization (Part 1)

CS342: Software Design. November 21, 2017

Fundamentals to Creating Architectures using ISO/IEC/IEEE Standards

RELEVANCE OF DESIGN PATTERNS TODAY

Design Pattern Detection

Introduction to Patterns and Frameworks

Design patterns. Valentina Presutti courtesy of Paolo Ciancarini

Architecture and Design Evolution

2.1 Design Patterns and Architecture (continued)

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

2.1 Design Patterns and Architecture (continued)

Adaptive System Infrastructure for Ultra-Large. Large-Scale Systems. SMART Conference, Thursday, March 6 th, 2008

Expanding Our Horizons. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 9 09/25/2011

UML and Objectorientation. Kristian Sandahl

CISC 322 Software Architecture

CPSC 310 Software Engineering. Lecture 11. Design Patterns

Design Pattern Detection

CS 520/620 Advanced Software Engineering Spring February 11, 2016

Observer Pattern. CS580 Advanced Software Engineering October 31, Yu Sun, Ph.D.

Overview of Java 8 Parallel Streams (Part 1)

Design Patterns. Observer Pattern*

Last Lecture. Lecture 17: Design Patterns (part 2) Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 4448/ Spring Semester, 2005

LABORATORY 1 REVISION

Lecture 7: Software Processes. Refresher: Software Always Evolves

Infrastructure Middleware (Part 3): Android Runtime Core & Native Libraries

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

Apply a Design Pattern

Patterns of learning

Lecture Notes UML UNIT-II. Subject: OOAD Semester: 8TH Course No: CSE-802

Java Barrier Synchronizers: CountDownLatch (Part 1)

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

Evolutionary Architecture and Design

Lecture 14: Design Patterns

Principles of Software Construction: Objects, Design and Concurrency. Introduction to Design. toad

Scenarios, Quality Attributes, and Patterns: Capturing and Using their Synergistic Relationships for Product Line Architectures

1 OBJECT-ORIENTED ANALYSIS

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

Bridge Pattern. Used to decouple an abstraction from its implementation so that the two can vary independently

Software Engineering with Objects and Components Open Issues and Course Summary

CS/CE 2336 Computer Science II

Lecture 8: Use Case -Driven Design. Where UML fits in

Systems Analysis and Design in a Changing World, Fourth Edition

The UML Extension Mechanisms

Patterns. Giovanni Sakti. in Software Engineering. Starqle

Overview of Activities

5 Object Oriented Analysis

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

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

The Design Patterns Matrix From Analysis to Implementation

MSO Lecture 12. Wouter Swierstra (adapted by HP) October 26, 2017

Review Software Engineering October, 7, Adrian Iftene

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

Software Design and Analysis CSCI 2040

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

Object Oriented Paradigm

Preliminaries. Part I

Compositional Model Based Software Development

Introduction to Design Patterns

NoSQL systems: introduction and data models. Riccardo Torlone Università Roma Tre

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

6 The MVC model. Main concepts to be covered. Pattern structure. Using design patterns. Design pattern: Observer. Observers

Advanced Topics in Software Engineering (02265) Ekkart Kindler

Transcription:

d.schmidt@vanderbilt.edu www.dre.vanderbilt.edu/~schmidt Professor of Computer Science Institute for Software Integrated Systems Vanderbilt University Nashville, Tennessee, USA

Topics Covered in this Module Motivate the importance of design experience & leveraging recurring design structure to become a master software developer 2

Topics Covered in this Module Motivate the importance of design experience & leveraging recurring design structure to become a master software developer Introduce patterns as a means of capturing & applying proven design experience that makes software more robust to change Subject state observerlist setdata getdata notify attach detach state = X; notify(); for all observers in observerlist do update() * Observer update ConcreteObserver update dosomething s->getdata() 3

Topics Covered in this Module Motivate the importance of design experience & leveraging recurring design structure to become a master software developer Introduce patterns as a means of capturing & applying proven design experience that makes software more robust to change Describe a process for successfully applying patterns to software development projects 4

Becoming a Master Software Developer Software methods emphasize design notations, such as UML Fine for specification & documentation 5

Becoming a Master Software Developer Software methods emphasize design notations, such as UML Fine for specification & documentation But software is more than drawing diagrams Good draftsmen are not necessarily good architects! 6

Software methods emphasize design notations, such as UML Fine for specification & documentation But software is more than drawing diagrams Good draftsmen are not necessarily good architects! Good software developers rely on design experience At least as important as knowledge of programming languages Becoming a Master Software Developer Subject state observerlist setdata getdata notify attach detach state = X; notify(); for all observers in observerlist do update() * Observer update ConcreteObserver update dosomething s->getdata() 7

Software methods emphasize design notations, such as UML Fine for specification & documentation But software is more than drawing diagrams Good draftsmen are not necessarily good architects! Good software developers rely on design experience At least as important as knowledge of programming languages Design experience can be codified via design & code reuse Design reuse: Match problem(s) to design experience & best practices Code reuse: Reify proven designs within a particular set of domains & development environments 8 Becoming a Master Software Developer Subject state observerlist setdata getdata notify attach detach state = X; notify(); for all observers in observerlist do update() * Observer update ConcreteObserver update dosomething s->getdata()

Leveraging Recurring Design Structures Well-designed software systems exhibit recurring structures that promote Abstraction Flexibility Reuse Quality Elegance Modularity Therein lies valuable design knowledge Challenge: extracting, documenting, communicating, applying, & preserving this knowledge without undue time, effort, & risk in the face of continual change to the software! 9

Making Software that s Robust to Changes Change is intrinsic to software development as requirements, use-cases, technologies, platforms, & quality goals evolve Robustness to change means that software can be modified locally without endangering overall structure It is a quality that reflects ease of evolution & maintenance costs What is needed is a means to address particular design aspects of software & allow controlled variation & evolution of these aspects 10

Key to Mastery: Knowledge of Software Patterns A patterns describes solution(s) to common problem(s) arising within a context by Naming a recurring design structure Jug Handle pattern 11

Key to Mastery: Knowledge of Software Patterns A patterns describes solution(s) to common problem(s) arising within a context by Naming a recurring design structure Subject Observer Observer pattern ConcreteObserver define a one-to-many dependency between objects so that when one object changes state, all dependents are notified & updated 12

Key to Mastery: Knowledge of Software Patterns A patterns describes solution(s) to common problem(s) arising within a context by Naming a recurring design structure Specifying design structure explicitly by identifying key classes/objects* Roles & relationships Dependencies Interactions Conventions Subject state observerlist setdata getdata notify attach detach state = X; notify(); Observer pattern for all observers in observerlist do update() * Observer update ConcreteObserver update dosomething s->getdata() *Interpret class & object loosely: patterns 13 are for more than OO languages!

Key to Mastery: Knowledge of Software Patterns A patterns describes solution(s) to common problem(s) arising within a context by Naming a recurring design structure Specifying design structure explicitly by identifying key classes/objects Roles & relationships Dependencies Interactions Conventions Abstracting from concrete design elements, e.g., problem domain, programming language, vendor, etc. Subject state observerlist setdata getdata notify attach detach state = X; notify(); Observer pattern for all observers in observerlist do update() * Observer update ConcreteObserver update dosomething s->getdata() 14

15 Key to Mastery: Knowledge of Software Patterns A patterns describes solution(s) to common problem(s) arising within a context by Naming a recurring design structure Specifying design structure explicitly by identifying key classes/objects Dependencies Roles & Relationships Interactions Conventions Abstracting from concrete design elements, e.g., problem domain, programming language, vendor, etc. Distilling & codifying knowledge gleaned from successful design experience Subject state observerlist setdata getdata notify attach detach state = X; notify(); Observer pattern for all observers in observerlist do update() * Observer update ConcreteObserver update dosomething s->getdata()

Common Characteristics of Patterns They are independent of programming languages & implementation techniques 16

Common Characteristics of Patterns They are independent of programming languages & implementation techniques They define micro-architectures i.e., a society of objects Subject state observerlist setdata getdata notify attach detach state = X; notify(); * Observer update ConcreteObserver update dosomething for all observers in observerlist do update() s->getdata() 17

They are independent of programming languages & implementation techniques They define micro-architectures i.e., a society of objects They aren t code or (concrete) designs, so they must be reified & applied in particular languages 18 Common Characteristics of Patterns Observer pattern in Java public class EventHandler extends Observer { public void update(observable obj, Object arg) { /* */ } public class EventSource extends Observable, implements Runnable { public void run() { /* */ notifyobservers(/* */); } EventSource eventsource = new EventSource(); EventHandler eventhandler = new Event_Handler(); eventsource.addobserver(eventhandler); Thread thread = new Thread(eventSource); thread.start();

They are independent of programming languages & implementation techniques They define micro-architectures i.e., a society of objects They aren t code or (concrete) designs, so they must be reified & applied in particular languages 19 Common Characteristics of Patterns Observer pattern in C++ (uses the GoF Bridge pattern with reference counting to simplify memory management & ensure exception-safe semantics) class Event_Handler : public Observer { public: virtual void update(observable obj, Object arg) { /* */ } class Event_Source : public Observable, public Runnable { public: virtual void run() { /* */ notify_observers(/* */); } Event_Source event_source = new Event_Source_Impl; Event_Handler event_handler = new Event_Handler_Impl; event_source->add_observer(event_handler); Thread thread = new Thread(event_source); thread->start();

They are independent of programming languages & implementation techniques They define micro-architectures i.e., a society of objects They aren t code or (concrete) designs, so they must be reified & applied in particular languages They are not methods, but can be used an adjunct to other methods e.g., Rational Unified Process, Agile, etc. There are also patterns for organizing effective software development teams & navigating other complex settings 20 Common Characteristics of Patterns

21 Common Parts of a Pattern Description Name & statement of pattern intent Problem addressed by pattern Including forces & applicability Solution Visual & textual descriptions of pattern structure & dynamics Consequences Pros & cons of applying the pattern Implementation guidance May include source code examples Known uses rule of three Related patterns Tradeoffs between alternative patterns See c2.com/cgi/wiki?patternforms for more info on pattern forms

To apply patterns successfully, software developers need to: Process for Applying Patterns Have broad knowledge of patterns relevant to their domain(s) 22

To apply patterns successfully, software developers need to: Process for Applying Patterns Have broad knowledge of patterns relevant to their domain(s) Evaluate trade-offs & impact of using certain patterns in their software Template Method pattern Strategy pattern 23

Process for Applying Patterns To apply patterns successfully, software developers need to: Have broad knowledge of patterns relevant to their domain(s) Evaluate trade-offs & impact of using certain patterns in their software Make design & implementation decisions about how best to apply the selected patterns Patterns may require slight modifications for particular contexts Content Observable state observerlist registerobserver unregisterobserver notifychange for all observers in observerlist do onchange() Content Observer onchange EventHandler onchange One use of the Observer Pattern in Android * 24

Process for Applying Patterns To apply patterns successfully, software developers need to: Have broad knowledge of patterns relevant to their domain(s) Evaluate trade-offs & impact of using certain patterns in their software Make design & implementation decisions about how best to apply the selected patterns Patterns may require modifications for particular contexts Context state observerlist registerreceiver unregisterreceiver sendbroadcast for all observers in observerlist do onreceive() Broadcast Receiver onreceive BroadcastHandler onreceive A different use of the Observer Pattern in Android * 25

Process for Applying Patterns To apply patterns successfully, software developers need to: Have broad knowledge of patterns relevant to their domain(s) Evaluate trade-offs & impact of using certain patterns in their software Make design & implementation decisions about how best to apply the selected patterns Patterns may require modifications for particular contexts 26 If (uniqueinstance == 0) uniqueinstance = new Singleton; return uniqueinstance; Singleton pattern vs. Double-Checked Locking Optimization Pattern class Singleton { public: static Singleton *instance () { // First check if (instance_ == 0) { Guard<Thread_Mutex> g(lock_); if (instance_ == 0) // Double check instance_ = new Singleton; } return instance_; } private: static Singleton *instance_; static Thread_Mutex lock_; };

To apply patterns successfully, software developers need to: Process for Applying Patterns Have broad knowledge of patterns relevant to their domain(s) Evaluate trade-offs & impact of using certain patterns in their software Make design & implementation decisions about how best to apply the selected patterns Patterns may require modifications for particular contexts Combine with other patterns & implement/integrate with code 27

Patterns support Design at a more abstract level Treat many class/object interactions as a conceptual unit Summary Emphasize design qua design, not (obscure) language features Provide ideal targets for design refactoring Variation-oriented design process 1. Determine which design elements can vary 2. Identify applicable pattern(s) 3. Vary patterns & evaluate trade-offs 4. Repeat 28 Patterns can be applied in all software lifecycle phases Analysis, design, & reviews Implementation & documentation Testing & optimization Reuse & refactoring Resist urge to brand everything as a pattern Articulate specific benefits & demonstrate general applicability e.g., find three different existing examples from code other than your own! Patterns often equated with OO languages, but can apply to non-oo languages