CS 520 Theory and Practice of Software Engineering Fall 2018

Similar documents
CS 520 Theory and Practice of Software Engineering Fall 2017

CS 320 Introduction to Software Engineering Spring March

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

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

CS 520/620 Advanced Software Engineering Fall September 27, 2016

CS 520 Theory and Practice of Software Engineering Fall 2018

CS 520 Theory and Practice of Software Engineering Fall 2017

An Introduction to Patterns

CS 320 Introduction to Software Engineering Spring March 06, 2017

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

Design Patterns Reid Holmes

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

SDC Design patterns GoF

Design Pattern and Software Architecture: IV. Design Pattern

CS 520 Theory and Practice of Software Engineering Fall 2018

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

Object-oriented Software Design Patterns

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

CSE 70 Final Exam Fall 2009

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

Design Patterns Reid Holmes

Design patterns. Jef De Smedt Beta VZW

THOMAS LATOZA SWE 621 FALL 2018 DESIGN PATTERNS

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

Composite Pattern. IV.4 Structural Pattern

Object-Oriented Design I - SOLID

Program to an Interface (a.k.a. - P2I) Not an Implementation

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

Program to an Interface, Not an Implementation

Pro Objective-C Design Patterns for ios

Exam in TDDB84: Design Patterns,

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

Introduction to Object Oriented Programming. (Hebrew University, CS / Spring 2012 )

Design Patterns Revisited

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

CS342: Software Design. November 21, 2017

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

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

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

Design Patterns (Composite, Iterator)

Admin. CS 112 Introduction to Programming. Recap: Exceptions. Summary: for loop. Recap: CaesarFile using Loop. Summary: Flow Control Statements

CS 112 Introduction to Programming

Game Architecture Revisited

Design Patterns. Gunnar Gotshalks A4-1

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

Applying the Observer Design Pattern

CS246 Software Abstraction and Specification Final Examination

SYLLABUS CHAPTER - 1 [SOFTWARE REUSE SUCCESS FACTORS] Reuse Driven Software Engineering is a Business

CS205: Scalable Software Systems

CS 351 Design of Large Programs Programming Abstractions

Chapter 6. Object- Oriented Programming Part II

09/08/2017 CS2530 INTERMEDIATE COMPUTING 9/8/2017 FALL 2017 MICHAEL J. HOLMES UNIVERSITY OF NORTHERN IOWA TODAY S TOPIC: Exceptions and enumerations.

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

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

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

CS 370 Design Heuristics D R. M I C H A E L J. R E A L E F A L L

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

CPSC 310: Sample Final Exam Study Questions 2014S1 (These are in addition to the Study Questions listed at the end of some lectures)

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

3 Product Management Anti-Patterns by Thomas Schranz

C++ (Non for C Programmer) (BT307) 40 Hours

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

About this exam review

COMP-202. Recursion. COMP Recursion, 2011 Jörg Kienzle and others

Topics in Object-Oriented Design Patterns

Design Patterns. (and anti-patterns)

Summary of the course lectures

Resolve: Generation of High Performance Sorting Architectures from High Level Synthesis

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

Documentation. Programming / Documentation Slide 42

Introduction to Software Engineering: Object Design I Reuse & Patterns

An Introduction to Patterns

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

DESIGN PATTERN - INTERVIEW QUESTIONS

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

Design Patterns (Composite)

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

2. The object-oriented paradigm

2.1 Design Patterns and Architecture (continued)

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

Design patterns. OOD Lecture 6

Using Design Patterns in Java Application Development

2.1 Design Patterns and Architecture (continued)

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

Final Exam Review (extended)

Top Down Design vs. Modularization

EINDHOVEN UNIVERSITY OF TECHNOLOGY

SOFTWARE PATTERNS. Joseph Bonello

the gamedesigninitiative at cornell university Lecture 12 Component Design

The Java language has a wide variety of modifiers, including the following:

Introduction to Computer Science Midterm 3 Fall, Points

Software LEIC/LETI. Lecture 10

Practice Problems. Review, with SOME solutions

Sorting. Quicksort analysis Bubble sort. November 20, 2017 Hassan Khosravi / Geoffrey Tien 1

Software Engineering

COURSE 2 DESIGN PATTERNS

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

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

Lecture 20: Design Patterns II

Transcription:

Today CS 520 Theory and Practice of Software Engineering Fall 208 Object Oriented Design Patterns Recap: Object oriented design principles Design problems & potential solutions Design patterns: What is a design pattern? Categories of design patterns Structural design patterns September 25, 208 Recap Object oriented design principles Information hiding (and encapsulation) Open/closed principle Liskov substitution principle Composition/aggregation over inheritance A first design problem Weather station revisited Current 30 day history Temp. sensor Reset Reset history button Controler: example What s a good design for the view? Simple weather station Current 30 day history 0/0 -> 0 0/02 -> - 5 0/03 -> -0 0/04 -> - 4 Reset Temp. sensor Reset Reset history button Temp. sensor Reset history button Controler 09/0,2 09/02,4

Weather station: view Weather station: view..n..n Simple Graph Complex -views:list<> +add(v:) Simple Graph Complex -views:list<> +add(v:) How do we need to implement draw(d:data)? public void draw(data d) { for ( v : views) { v.draw(d); Design pattern: Design pattern:..n..n Iterate over all composed components (comps), call operation() on each, and potentially aggregate the results. CompB -comps:collection<> +addcomp(c:) +removecomp(c:) CompB -comps:collection<> +addcomp(c:) +removecomp(c:) What is a design pattern? Addresses a recurring, common design problem. Provides a generalizable solution. Provides a common terminology. What is a design pattern? Addresses a recurring, common design problem. Provides a generalizable solution. Provides a common terminology. Pros Improves communication and documentation. Toolbox for novice developers. Cons Risk of over-engineering. Potential impact on system performance. More than just a name for common sense and best practices. 2

Design patterns: categories. Structural 2. Behavioral Visitor Template method 3. Creational Singleton Factory (method) new (); while((b=is.read())!= -) { new (); while((b=is.read())!= -) { new (); while((b=is.read())!= -) { Problem: filesystem I/O is expensive Problem: filesystem I/O is expensive Solution: use a buffer! Why not simply implement the buffering in the client or subclass? Design pattern: new Buffered( new ()); while((b=is.read())!= -) { Still returns one byte (int) at a time, but from its buffer, which is filled by calling read(buf:byte[]). Buffered -buffer:byte[] +Buffered(is:) CompB -decorated: +(d:) 3

vs. Recap: vs...n..n -comps:collection<> +addcomp(c:) +removecomp(c:) -decorated: +(d:) -comps:collection<> +addcomp(c:) +removecomp(c:) -decorated: +(d:) Find the median in an array of doubles Examples: median([, 2, 3, 4, 5]) =??? median([, 2, 3, 4]) =??? Find the median in an array of doubles Examples: median([, 2, 3, 4, 5]) = 3 median([, 2, 3, 4]) = 2.5 Algorithm Input: array of length n Output: median Find the median in an array of doubles Examples: median([, 2, 3, 4, 5]) = 3 median([, 2, 3, 4]) = 2.5 Algorithm Input: array of length n Output: median. Sort array 2. if n is odd return ((n+)/2)th element otherwise return arithmetic mean of (n/2)th element and ((n/2)+)th element Median computation: naive solution public static void main(string args) { System.out.println(median(,2,3,4,5)); public static double median(double numbers) { int n = numbers.length; boolean swapped = true; while(swapped) { swapped = false; for (int i = ; i<n; ++i) { if (numbers[i-] > numbers[i]) { swapped = true; if (n%2 == 0) { return (numbers[(n/2) - ] + numbers[n/2]) / 2; else { return numbers[n/2]; What s wrong with this design? How can we improve it? 4

Ways to improve One possible solution: template method pattern : Monolithic version, static context. 2: Extracted sorting method, non-static context. 3: Proper package structure and visibility, extracted main method. 4: Proper testing infrastructure and build system. AbstractMedian {abstract + median(a:double[]):double Italics indicate an abstract method. SimpleMedian One possible solution: template method pattern One possible solution: template method pattern AbstractMedian {abstract + median(a:double[]):double The template method (median) implements the algorithm but leaves the sorting of the array undefined. AbstractMedian {abstract + median(a:double[]):double Should the median method be final? The template method (median) implements the algorithm but leaves the sorting of the array undefined. SimpleMedian The concrete subclass only needs to implement the actual sorting. SimpleMedian The concrete subclass only needs to implement the actual sorting. Another solution: strategy pattern Template method pattern vs. strategy pattern Median +median(a:double[]):double Sorter +sort(array:double[]) Two solutions to the same problem StrategyMedian -sortstrategy:sorter +median(a:double[]):double +setsorter(s:sorter) HeapSort +sort() QuickSort +sort() median delegates the sorting of the array to a sortstrategy What are the differences, pros, and cons? 5

Template method pattern vs. strategy pattern Two solutions to the same problem --Controller revisited Design patterns in a MVC architecture Template method Behavior selected at compile time. Template method is usually final. Strategy Behavior selected at runtime. Composition/aggregation over inheritance. Controller --Controller revisited Design patterns in a MVC architecture --Controller revisited Design patterns in a MVC architecture Strategy Controller Controller??? Observer pattern Observer pattern Problem solved: A one-to-many dependency between objects should be defined without making the objects tightly coupled. When one object changes state, an open-ended number of dependent objects are updated automatically. One object can notify an open-ended number of other objects. Observable {abstract # observers:set<observer> + register(o:observer) + unregister(o:observer) + statechanged() MyObservable - state:state + getstate():state + setstate(state:state) Observer MyObserver 6

Observer pattern Observable {abstract # observers:set<observer> + register(o:observer) + unregister(o:observer) + statechanged() Observer MyObservable - state:state + getstate():state + setstate(state:state) MyObserver Variation: pass incremental changes or the state to update method. 7