CSC 301H, Introduction to Software Engineering

Similar documents
Page 1. Chapter 8, Object Design: Design Patterns II. Recall: Why reusable Designs? Definitions. A Taxonomy of Design Patterns

Design Patterns 2. Page 1. Software Requirements and Design CITS 4401 Lecture 10. Proxy Pattern: Motivation. Proxy Pattern.

Lecture 21: Design Patterns III

Design Patterns. Bernd Bruegge. Carnegie Mellon University Department of Computer Science 15 October 1998

What is Design Patterns?

Creational Design Patterns

Object-Oriented Oriented Programming Factory Method Pattern Abstract Factory Pattern. CSIE Department, NTUT Woei-Kae Chen

The GoF Design Patterns Reference

Dr. Xiaolin Hu. Review of last class

Introduction and History

What is Design Patterns?

6.3 Patterns. Definition: Design Patterns

CS 2720 Practical Software Development University of Lethbridge. Design Patterns

Java OOP (SE Tutorials: Learning the Java Language Trail : Object-Oriented Programming Concepts Lesson )

2.1 Design Patterns and Architecture (continued)

2.1 Design Patterns and Architecture (continued)

What is Design Patterns?

Lecture 20: Design Patterns II

Second Midterm Review

8. Object Design: Reusing Pattern Solutions

Design patterns. OOD Lecture 6

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

Creational Patterns for Variability

Chapter 8, Object Design: Reusing Pattern Solutions

Design Patterns. Softwaretechnik. Matthias Keil. Albert-Ludwigs-Universität Freiburg

Design Patterns. Software Engineering. Sergio Feo-Arenis slides by: Matthias Keil

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

Laboratorio di Tecnologie dell'informazione. Ing. Marco Bertini

Design Patterns. Design Patterns

Singleton, Factory Method, Abstract Factory, Named Constructor. Using one or more base classes to hide details from the client

Brief Note on Design Pattern

Review of last class. 1.Class inheritance versus interface inheritance 2.Inheritance versus composition. Dr. Xiaolin Hu

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

Exam Questions. Object-Oriented Design, IV1350. Maximum exam score is 100, grade limits are as follows. Score Grade 90 A 80 B 70 C 60 D 50 E

Common Architectures and Design Patterns

Design Pattern- Creational pattern 2015

Universiti Malaysia Perlis

An Introduction to Patterns

2/17/04 Doc 8 Adapter & Strategy slide # 1

CHAPTER 6: CREATIONAL DESIGN PATTERNS

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

Softwaretechnik. Design Patterns. Matthias Keil. Albert-Ludwigs-Universität Freiburg

Topics in Object-Oriented Design Patterns

Creational Patterns. Factory Method (FM) Abstract Factory (AF) Singleton (SI) Prototype (PR) Builder (BU)

CS 335 Java Programming Controls. Fall 2007

Object Oriented Design and Programming Revision

Softwaretechnik. Design Patterns. Stephan Arlt SS University of Freiburg. Stephan Arlt (University of Freiburg) Softwaretechnik SS / 47

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

Laboratorio di Progettazione di Sistemi Software Design Pattern Creazionali. Valentina Presutti (A-L) Riccardo Solmi (M-Z)

Java Technologies. Lecture III. Valdas Rapševičius. Vilnius University Faculty of Mathematics and Informatics

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

Sri Vidya College of Engineering & Technology

Java Programming Tutorial 1

Design Patterns Reid Holmes

Lecture 13: Design Patterns

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

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

Class, Variable, Constructor, Object, Method Questions

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

Design Patterns Reid Holmes

Design of Software Systems (Ontwerp van SoftwareSystemen) Design Patterns Reference. Roel Wuyts

Software Engineering Design - Summary

PROGRAMMING FUNDAMENTALS

Lecture VI: Distributed Objects. Remote Method Invocation

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

Chair of Software Engineering. Languages in Depth Series: Java Programming. Prof. Dr. Bertrand Meyer. Exercise Session 3

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

Factory Method. Comp435 Object-Oriented Design. Factory Method. Factory Method. Factory Method. Factory Method. Computer Science PSU HBG.

Software Engineering Design & Construction

Tutorial 02: Writing Source Code

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

CS 520 Theory and Practice of Software Engineering Fall 2018

Java Tutorial. Saarland University. Ashkan Taslimi. Tutorial 3 September 6, 2011

THOMAS LATOZA SWE 621 FALL 2018 DESIGN PATTERNS

Introduction to Software Engineering: Object Design I Reuse & Patterns

Design Pattern and Software Architecture: IV. Design Pattern

Design issues: abstraction and patterns Strategy Pattern Singleton Pattern. CSIE Department, NTUT Woei-Kae Chen

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

About this exam review

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

From Patterns to Components: The Factory Library Example

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

Object-oriented Software Design Patterns

GOF Patterns Applied

Outline. EEC-681/781 Distributed Computing Systems. The OSI Network Architecture. Inter-Process Communications (IPC) Lecture 4

Outline. Object Oriented Programming. Course goals. Staff. Course resources. Assignments. Course organization Introduction Java overview Autumn 2003

(c) Bartosz Walter 1

Provide an interface for creating families of related or dependent objects without specifying their concrete classes

CS 335 Lecture 02 Java Programming

Learning the Java Language. 2.1 Object-Oriented Programming

Object Oriented Programming with c++ Question Bank

CS 520 Theory and Practice of Software Engineering Fall 2017

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

The Factory Method Pattern

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

Page 1. Human-computer interaction. Lecture 2: Design & Implementation. Building user interfaces. Users and limitations

Object-Oriented Design

Programming by Delegation

Pace University. Fundamental Concepts of CS121 1

CS 5523 Operating Systems: Remote Objects and RMI

Transcription:

CSC 301H, Introduction to Software Engineering Presented by Soheil Hassas Yeganeh Slides By Golnaz Elahi

Outline Design Pattern Concept Types of Design Patterns Overview of some Patterns: Abstract Factory Observer Command Strategy

Design Pattern Concept A design pattern is a template solution to a recurring design problem. Reusable design knowledge in form of Problem, Condition, Solution A design pattern expresses an idea rather than a fixed class combination.

Types of Design Patterns Creational Patterns: Creating a collection of objects Creating many versions of the collection at runtime Constraining the objects created Structural pattern: Representing a collection of related objects Controlling constraints on the number or style of objects, constructors, using external or distributed functionality, Behavioral pattern: Capturing behavior among a collection of objects A collection of objects exhibit functionality, separation of behavior from the object, interfaces without references.

Abstract Factory Pattern Consider a user interface toolkit that supports multiple looks and feel standards such as Motif, Windows 95 or the finder in MacOS. How can you write a single user interface and make it portable across the different look and feel standards for these window managers? Consider a facility management system for an intelligent house that supports different control systems such as Siemens Instabus, Johnson & Control Metasys or Zumtobe s proprietary standard. How can you write a single control system that is independent from the manufacturer?

Abstract Factory Pattern Goals: Create a family of related objects chosen at runtime from several possible families. Independence from Initialization or Representation The system should be independent of how its products are created, composed or represented

AbstractFactory AbstractProductA Client CreateProductA CreateProductB ProductA1 ProductA2 ConcreteFactory1 AbstractProductB CreateProductA CreateProductB ProductB1 ProductB2 ConcreteFactory2 CreateProductA CreateProductB Initiation Assocation: Class ConcreteFactory2 initiates the associated classes ProductB2 and ProductA2

Abstract Factory Pattern

In between What is an interface? Public interface Bicycle { void changegear(int newvalue); void speedup(int increment); void applybrakes(int decrement); } Public class ACMEBicycle implements Bicycle { // remainder of this class implemented as before }

Observer Pattern

Analyzing a Java Example GUI Scenario: Two windows have been created First (InputForm) is for user input; Second (DisplayForm) is for display. When the data has been entered in the textfield in the first, the second window gets the message and display it with a dialog. Inner classes are used to handle observer pattern

Observer Implementation in Example - Structure

Observer Implementation in Example Behavior

Strategy Pattern Many different algorithms exists for the same task. Like: Breaking a stream of text into lines Parsing a set of tokens into an abstract syntax tree Sorting a list of customers The different algorithms will be appropriate at different times Rapid prototyping vs delivery of final product We don t want to support all the algorithms if we don t need them If we need a new algorithm, we want to add it easily without disturbing the application using the algorithm.

Policy Context ContextInterface() * Strategy AlgorithmInterface ConcreteStrategyA AlgorithmInterface() ConcreteStrategyB AlgorithmInterface() ConcreteStrategyC AlgorithmInterface() Policy decides which Strategy is best given the current Context

Applying a Strategy Pattern in a Database Application Database Search() Sort() Strategy * Strategy Sort() BubbleSort Sort() QuickSort Sort() MergeSort Sort()

Strategy Pattern

Strategy Pattern // MainApp test application class MainApp { public static void main(string[] args) { Context context; // Three contexts following different strategies context = new Context(new ConcreteStrategyA()); context.execute(); context = new Context(new ConcreteStrategyB()); context.execute(); context = new Context(new ConcreteStrategyC()); context.execute(); }

Strategy Pattern interface IStrategy { void execute(); }

Strategy Pattern class ConcreteStrategyA implements IStrategy { public void execute() { System.out.println( "Called ConcreteStrategyA.execute()" ); } } class ConcreteStrategyB implements IStrategy { public void execute() { System.out.println( "Called ConcreteStrategyB.execute()" ); } } class ConcreteStrategyC implements IStrategy { public void execute() { System.out.println( "Called ConcreteStrategyC.execute()" ); }

Strategy Pattern class Context { IStrategy strategy; // Constructor public Context(IStrategy strategy) { this.strategy = strategy; } } public void execute() { strategy.execute(); }

Strategy Pattern

Proxy Pattern What is expensive? Object Creation Object Initialization Defer object creation and object initialization to the time you need the object Proxy pattern: Reduces the cost of accessing objects Uses another object ( the proxy ) that acts as a standin for the real object The proxy creates the real object only if the user asks for it

Proxy pattern Subject Request() Proxy Request() realsubject RealSubject Request() Interface inheritance is used to specify the interface shared by Proxy and RealSubject. Delegation is used to catch and forward any accesses to the RealSubject (if desired) Proxy patterns can be used for lazy evaluation and for remote invocation. Proxy patterns can be implemented with a Java interface.

Command Pattern You want to build a user interface You want to provide menus You want to make the user interface reusable across many applications You cannot hardcode the meanings of the menus for the various applications The applications only know what has to be done when a menu is selected. Such a menu can easily be implemented with the Command Pattern

Client Invoker Command execute() Receiver action() binds ConcreteCommand execute() Client creates a ConcreteCommand and binds it with a Receiver. Client hands the ConcreteCommand over to the Invoker which stores it. The Invoker has the responsibility to do the command ( execute or undo ).