Tuesday, October 4. Announcements

Similar documents
Design Patterns. An introduction

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

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

What is Design Patterns?

Using Design Patterns in Java Application Development

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

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

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

Thursday, October 13. Announcements

DESIGN PATTERN - INTERVIEW QUESTIONS

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

SDC Design patterns GoF

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

Design Patterns. CSC207 Fall 2017

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

A few important patterns and their connections

Plan. A few important patterns and their connections. Singleton. Singleton: class diagram. Singleton Factory method Facade

Design Patterns. CSC207 Winter 2017

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

What is Design Patterns?

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

Design Patterns. CSC207 Fall 2017

Object-oriented Software Design Patterns

Design Patterns. Gunnar Gotshalks A4-1

Lectures 24 and 25 Introduction to Architectural Styles and Design Patterns

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

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

Introduction to Software Engineering: Object Design I Reuse & 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

Object-Oriented Oriented Programming

Topics in Object-Oriented Design Patterns

What is Design Patterns?

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

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

3 Product Management Anti-Patterns by Thomas Schranz

An Introduction to Patterns

Applying the Observer Design Pattern

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

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

Object Oriented Paradigm

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

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

CPSC 310 Software Engineering. Lecture 11. Design Patterns

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

CS/CE 2336 Computer Science II

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

CS251 Software Engineering Lectures 18: Intro to DP

A Rapid Overview of UML

The GoF Design Patterns Reference

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

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

Object-Oriented Design

An Introduction to Patterns

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

A Reconnaissance on Design Patterns

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

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

Lecture 13: Design Patterns

Lecture 20: Design Patterns II

Design patterns. OOD Lecture 6

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

Software Engineering I (02161)

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

25.1 Introduction Façade Design Pattern Identification Problem Structure Participants...

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

Object-Oriented Design

Design Patterns. SE3A04 Tutorial. Jason Jaskolka

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

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

CHAPTER 6: CREATIONAL DESIGN PATTERNS

Development and Implementation of Workshop Management System Application to Explore Combing Multiple Design Patterns

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

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

Information systems modelling UML and service description languages

6.3 Patterns. Definition: Design Patterns

INSTITUTE OF AERONAUTICAL ENGINEERING

A Primer on Design Patterns

Applying Design Patterns to SCA Implementations

Review Software Engineering October, 7, Adrian Iftene

Patterns. Erich Gamma Richard Helm Ralph Johnson John Vlissides

APPLYING DESIGN PATTERNS TO SCA IMPLEMENTATIONS

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

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

Design Patterns Reid Holmes

Applying the Decorator Design Pattern

The Design Patterns Matrix From Analysis to Implementation

Overview of Patterns: Introduction

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

An Expert System for Design Patterns Recognition

Design Patterns: Structural and Behavioural

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

Design Patterns #3. Reid Holmes. Material and some slide content from: - GoF Design Patterns Book - Head First Design Patterns

SOFTWARE PATTERNS. Joseph Bonello

Applying the Factory Method Design Pattern

Creational Design Patterns

CS 247: Software Engineering Principles. Design Patterns

1 Software Architecture

Software Engineering I (02161)

Introduction and History

Design Patterns. (and anti-patterns)

Transcription:

Tuesday, October 4 Announcements www.singularsource.net Donate to my short story contest UCI Delta Sigma Pi Accepts business and ICS students See Facebook page for details Slide 2 1

Design Patterns Design Patterns Reusable design component First codified by the Gang of Four in 1995 Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides Concept taken from architecture A Pattern Language by Christopher Alexander a three-part rule, which expresses a relation between a certain context, a problem, and a solution. Original Gang of Four book described 23 patterns More have been added Other authors have written books Slide 4 2

Design Patterns Template Context General situation in which the pattern applies Problem The main difficulty being tackled Forces Issues or concerns that need to be considered. Includes criteria for evaluating a good solution. Solution Recommended way to solve the problem in the context. The solution balances the forces The following are optional Antipatterns Common mistakes to avoid Related Patterns Similar patterns; could be alternated solutions or work with the pattern References Source of pattern Who developed or inspired the pattern Slide 5 Gang of Four Design Patterns Creational Patterns Abstract Factory Builder Factory Method Prototype Singleton Structural Patterns Adapter Bridge Composite Decorator Façade Flyweight Proxy Behavioral Patterns Chain of Responsibility Command Interpreter Iterator Mediator Memento Observer State Strategy Template Method Visitor Slide 6 3

Chain of Responsibility Exception handling Try/catch/throw blocks Iterator Container classes Observer Listeners in GUIs Patterns in Java Slide 7 Gang of Four Design Patterns Creational Patterns Abstract Factory Builder Factory Method Prototype Singleton Structural Patterns Adapter Bridge Composite Decorator Façade Flyweight Proxy Behavioral Patterns Chain of Responsibility Command Interpreter Iterator Mediator Memento Observer State Strategy Template Method Visitor Slide 8 4

The Observer Pattern Context When an association is created between two classes, the code for the classes becomes inseparable. If you want to reuse one class, then you also have to reuse the other. Problem How do you reduce the interconnection between classes, especially between classes that belong to different modules or subsystems? Forces You want to maximize the flexibility of the system to the greatest extent possible Slide 9 The Observer Pattern Solution «Observable» addobserver notifyobservers * * «interface» «Observer» update «ConcreteObservable» «ConcreteObserver» Observable * * «interface» Observer Forecaster Observers are notified when a new prediction is ready WeatherViewer Slide 10 5

Observer Antipatterns (Don t do this) Connect an observer directly to an observable so that they both have references to each other. Make the observers subclasses of the observable. Reference Gang of Four Slide 11 Observer in Java Observer interface and Observable class exist java.util.observer and java.util.observable But people usually implement their own Usually can t or don t want to sub-class from Observable Can t have your own class hierarchy and multiple inheritance is not available Has been replaced by the Java Delegation Event Model (DEM) Passes event objects instead of update/notify Listener is specific to GUI classes Slide 12 6

Thursday, October 4 Announcements Tuesday is not Remembrance Day nor Veteran s Day But you still get the day off Slide 14 7

The Façade Pattern Context Often, an application contains several complex packages. A programmer working with such packages has to manipulate many different classes Problem How do you simplify the view that programmers have of a complex package? Forces It is hard for a programmer to understand and use an entire subsystem If several different application classes call methods of the complex package, then any modifications made to the package will necessitate a complete review of all these classes. Slide 15 The Façade Pattern Solution Slide 16 8

The Façade Pattern Solution Provide a simple interface to a complex subsystem. Decouple the classes of the subsystem from its clients and other subsystems, thereby promoting subsystem independence and portability Slide 17 Using the Façade Pattern Hides implementation details Promotes weak coupling between the subsystem and its clients. Reduces compilation dependencies in large software systems Does not add any functionality, it just simplifies interfaces Does not prevent clients from accessing the underlying classes. Slide 18 9

Façade Example Slide 19 The Singleton Pattern Context It is very common to find classes for which only one instance should exist (singleton) Problem How do you ensure that it is never possible to create more than one instance of a singleton class? Forces The use of a public constructor cannot guarantee that no more than one instance will be created. The singleton instance must also be accessible to all classes that require it Slide 20 10

The Singleton Pattern Solution Slide 21 Singleton Example Pattern «Singleton» theinstance getinstance This is the code for getinstance Instantiation of Pattern WindowMgr thewindowmgr WindowMgr «private» getinstance if (thewindowmgr==null) thewindowmgr= new WindowMgr(); return thewindowmgr; Constructor for WindowMgr is private getinstance is public and static thewindowmgr is private and static Slide 22 11

Singleton Design Pattern public class WindowMgr { private static WindowMgr thewindowmgr; private String windowlabel; private WindowMgr (){ } // Lazy instantiation public static synchronized WindowMgr getinstance(){ if (thewindowmgr == null){ thewindowmgr = new WindowMgr(); } return thewindowmgr; }... } Slide 23 Singleton Design Pattern public class WindowMgr { // Eager instantiation private static WindowMgr thewindowmgr = new WindowMgr(); private String windowlabel; private WindowMgr (){ } public static synchronized WindowMgr getinstance(){ return thewindowmgr; }... } Slide 24 12

Questions Why do you need the getinstance method? Why isn t it enough to just make thewindowmgr static (i.e. one per class)? This results in extra instances of WindowMgr, but still only one underlying thewindowmgr Why do you need an instance of WindowMgr at all? Why not just make all the methods static? May need an instance, e.g. as an observer, for callbacks More flexible when you discover later that you don t want WindowMgr to be a singleton any more Slide 25 Drawbacks Need to add synchronization to getinstance Race condition could occur in if block Sub-classing becomes complicated Private constructor violates normal Java design principles Could change constructor to protected, but that would violate the security provided Make a sub-class that is identical to parent Can have lots of pseudo-windowmgrs running around Alternatively, each sub-class has own getinstance method Also need to prevent cloning by overriding Cloneable interface Erich Gamma doesn t like Singleton any more Slide 26 13

Singleton Design Pattern Related Patterns Factory and Façade Reference Gang of Four Slide 27 Strategy Design Pattern Context Define a family of algorithms, so they are interchangeable. Also Known As Policy Problem How to design for varying, but related algorithms or policies? How to design for the ability to change the algorithms or policies? Solution Define each algorithm/policy/strategy in a separate class with a common interface Slide 28 14

Structure Strategy Design Pattern Slide 29 Example Slide 30 15

Example Slide 31 Strategy Design Pattern Participants Strategy interface, concrete Strategy, and Context/client Consequences Provides an alternative to subclassing the Context class to get a variety of algorithms or behaviors Eliminates large conditional statements Provides a choice of implementations for the same behavior Increases the number of objects All algorithms must use the same Strategy interface Implementation Can use an Abstract Factory to create a Strategy Slide 32 16

The Importance of Ignorance Context Everyone is ignorant about something-- often many things The first step in becoming an intelligent ignoramus is to understand ignorance Slide 34 17

Armour s Orders of Ignorance Zeroth Order Ignorance (0OI): Lack of ignorance. I have 0OI when I provably know something. First Order Ignorance (1OI): Lack of knowledge. I have 1OI when I do not know something. Second Order Ignorance (2OI): Lack of awareness. I have 2OI when I do not know that I do not know something. Third Order Ignorance (3OI): Lack of Process. I have 3OI when I do not know of a suitably efficient way to find out that I do not know that I do not know something. Fourth Order Ignorance (4OI): Meta ignorance. I have 4OI when I do not know about the Five Orders of Ignorance. Slide 35 Zeroth Order Ignorance (0OI) Lack of Ignorance I have Zeroth Order Ignorance (0OI) when I know something and can demonstrate my lack of ignorance in some tangible form. 0OI is provable and proven knowledge that is deemed correct by some qualified agency. In software this means that the knowledge is invariably factored into usable form. In all forms of knowledge there must be some external proof element that qualifies the knowledge as being correct. Examples Trivia Building a system that satisfies the user Ability to sail Slide 36 18

First Order Ignorance (1OI) Lack of Knowledge I have First Order Ignorance (1OI) when I do not know something and I can readily identify that fact. 1OI is basic ignorance or lack of knowledge. Example Speaking Russian Slide 37 Second Order Ignorance (2OI) Lack of Awareness I have Second Order Ignorance (2OI) when I do not know that I do not know something. That is to say, not only am I ignorant of something (I have 1OI), I am unaware of what it is I am ignorant about. I do not know enough to know what it is that I do not know. Example I cannot give a good example of 2OI, of course. Do you need a will or a trust? Slide 38 19

Third Order Ignorance (3OI) Lack of Process I have Third Order Ignorance (3OI) when I do not know of a suitably efficient way to find out that I do not know that I do not know something, which is lack of a suitable knowledgegathering process. This presents me with a major problem: If I have 3OI, I do not know of a way to find out that there are things that I do not know that I do not know. Therefore, I cannot change those things that I do not know that I do not know into either things that I know, or at least things that I know that I do not know, as a step toward converting the things that I know that I do not know into things that I know. Example Design Investigative journalism Slide 39 Fourth Order Ignorance (4OI): Meta Ignorance I have Fourth Order Ignorance (4OI) when I do not know about the Five Orders of Ignorance. I do not have this kind of ignorance, and now neither do you. Knowledge is highly and intrinsically recursive-- to know about anything, you must first know about other things which define what you know. Slide 40 20

Reveals Ignorance Intelligence Reduces Ignorance Assumptions Examples Richard Feynman Dan Berry Asking Questions Slide 41 21