SE2811 Software Component Design Dr. Rob Hasker

Slides:



Advertisements
Similar presentations
ANU COMP2110 Software Design in 2003 Lecture 16Slide 1 Lecture 16: Introduction to design patterns 1What are they? 2Where do they come from? 3Why study.
Advertisements

SE2811 Week 7, Class 2 The Gang of Four and more … Lab Thursday: Quiz SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder.
James Tam Introduction To Design Patterns You will learn about design techniques that have been successfully applied to different scenarios.
Fundamentals of Software Development 1Slide 1 Gang of Four The beginnings… The original “patterns” idea was from architecture – there are repeatable patterns.
Design Patterns In OPM Presented by: Galia Shlezinger Instructors: Prop. Dov Dori, Dr. Iris Berger.
Visual Basic: An Object Oriented Approach 11 – Patterns in object oriented programming.
13-Jul-15 Refactoring II. Books Design Patterns is the classic book by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides Basically a catalog.
Programming With Java ICS201 University Of Hail1 Chapter 12 UML and Patterns.
Chapter Five An Introduction to Design Patterns Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Intoduction to Unit Testing Using JUnit to structure Unit Testing SE-2030 Dr. Rob Hasker 1 Based on material by Dr. Mark L. Hornick.
BTS430 Systems Analysis and Design using UML Design Patterns.
ANU COMP2110 Software Design in 2004 Lecture 15Slide 1 COMP2110 in 2004 Software Design Lecture 15: Software design patterns (2) 1What are design patterns?
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
CS 325: Software Engineering February 12, 2015 Applying Responsibility-Assignment Patterns Design Patterns Situation-Specific Patterns Responsibility-Assignment.
Patterns and Reuse. Patterns Reuse of Analysis and Design.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Object Oriented.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
CS2852 Week 3, Class 2 Today Stacks Queues SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
Advanced Object-Oriented Design Patterns and Architectures Part One COEN396A John Xiao
Design Patterns: Elements of Reusable Object- Orientated Software Gamma, Helm, Johnson, Vlissides Presented By: David Williams.
CS251 – Software Engineering Lectures 18: Intro to DP Slides by Rick Mercer, Christian Ratliff, Oscar Nierstrasz and others 1 و ابتغ فيما آتاك الله الدار.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 3: Basing Software Development on Reusable Technology.
SE-2811 Software Component Design Week 1, Day 2 Making teams Warm-up exercise Design pattern defined SE-2811 Dr. Josiah Yoder Slide style: Dr. Hornick.
Systems Requirements SE 3821 Design? Algorithms CS 2852.
Week 9, Day 2 Object-oriented Design Acknowledgement: These slides by Dr. Hasker SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors:
Model-View-Controller A Design Pattern SE-2030 Dr. Rob Hasker 1 Based on slides written by Dr. Mark L. Hornick Used with permission.
SE-2811 Software Component Design Week 1, Day 1 Design pattern defined Code that needs a design pattern… SE-2811 Dr. Josiah Yoder Slide style: Dr. Hornick.
1 Lecture Material Design Patterns Visitor Client-Server Factory Singleton.
Elaboration: Iteration 2. Elaboration: Iteration 2 Basics Iteration 1 ends with : All the software has been tested: The idea in the UP is to do early,
Slide design: Dr. Mark L. Hornick
Introduction To Design Patterns
Design Patterns: MORE Examples
Slide design: Dr. Mark L. Hornick
The Object-Oriented Thought Process Chapter 15
MPCS – Advanced java Programming
A Brief Introduction to Design Patterns
Week 2, Day 1: The Factory Method Pattern
The Singleton Pattern SE-2811 Dr. Mark L. Hornick.
Design Patterns Introduction
Testing and Debugging.
Repeating code We could repeat code we need more than once: i = 1 print (i) i += 1 print (i) #… stop when i == 9 But each line means an extra line we might.
SE-2811 Software Component Design
1. Where to start SE2811 Software Component Design Dr. Josiah Yoder
CSE373: Data Structures & Algorithms Lecture 25: Software-Design Interlude – Preserving Abstractions Catie Baker Spring 2015.
3. Object-oriented Design
08/15/09 Design Patterns James Brucker.
Chapter 22 Object-Oriented Design
Week 7, Class 1: The Command Pattern (cont.)
Basic Object Oriented Approach
CSE373: Data Structures & Algorithms Lecture 16: Software-Design Interlude – Preserving Abstractions Dan Grossman Fall 2013.
SE2811 Software Component Design Dr. Rob Hasker
7. Decorator SE2811 Software Component Design
8. Observer Pattern SE2811 Software Component Design
4: Object-oriented Analysis & Design
SE2811 Software Component Design Dr. Rob Hasker
Introduction to Design Patterns
13. Composite Pattern SE2811 Software Component Design
SE-2811 Software Component Design
Polling vs. Interrupts CS2852 4/21/2019
Review of Previous Lesson
Computational Thinking
11. MVC SE2811 Software Component Design
Introduction To Design Patterns
Week 8, Class 3: Model-View-Controller
11. MVC SE2811 Software Component Design
16. Visitors SE2811 Software Component Design
5. Strategy, Singleton Patterns
16. Visitors SE2811 Software Component Design
Presentation transcript:

SE2811 Software Component Design Dr. Rob Hasker Reading: Java Design Pattern Essentials, Chapter 1 1. Where to start

SE 2811: Software Component Design CS-1020 6/6/2019 SE 2811: Software Component Design Systems Requirements SE 3821 Design? Algorithms CS 2852 Opportunities for reuse Classic reuse models: requirements, algorithms Print Dr. Mark L. Hornick

SE 2811: Software Component Design CS-1020 6/6/2019 SE 2811: Software Component Design Systems Requirements SE 3821 Design: SE 2811 Algorithms CS 2852 Opportunities for reuse Classic reuse models: requirements, algorithms 2811: reusing designs Print Dr. Mark L. Hornick

SE 2811: Software Component Design CS-1020 6/6/2019 SE 2811: Software Component Design Systems Requirements SE 3821 Design: SE 2811 Algorithms CS 2852 Opportunities for reuse Classic reuse models: requirements, algorithms 2811: reusing designs 1994: Gang of 4 Gamma, Helm, Johnson, Vlissides Print Design pattern: general, reusable solution to a commonly occurring problem in software design Dr. Mark L. Hornick

A real-life example How to get from Milwaukee to Chicago? Identify at least four methods What are common elements? What can differ? How do we compare them? Are these algorithms? Algorithm: sequence of steps to be followed to calculate a result

Example #2 Problem: Workplace, home traffic pattern: travel to frequently accessed objects If objects scattered, flow of life is awkward Items forgotten, misplaced

Example #2 Problem: Workplace, home traffic pattern: travel to frequently accessed objects If objects scattered, flow of life is awkward Items forgotten, misplaced Solution: Waist-high shelves around at least part of main rooms in which people live & work They should be long, 22-40 cm deep Shelves or cupboard underneath Interrupt shelf for seats, windows, doors

Example #2 Note features: Shelf color, material not important to the structure Not an algorithm/not blueprints Architectural design pattern Are there times when the pattern is a poor choice? Each pattern: Solves a recurring problem Tradeoffs: advantages, disadvantages to applying

Software example public class StereoController {     private Volume volume;     private Equalizer equalizer;     public StereoController(Volume volume, Equalizer equalizer) {         this.volume = volume;         this.equalizer = equalizer;     }                                 public changeVolume(int ticks) {         volume.adjust(ticks);     }     public changeChannel(int channel, int ticks) {         if ( equalizer != null )             equalizer.getChannel(channel).adjust(ticks); }

Software example Models core elements of stereo: volume control, equalizer public class StereoController {     private Volume volume;     private Equalizer equalizer;     public StereoController(Volume volume, Equalizer equalizer) {         this.volume = volume;         this.equalizer = equalizer;     }                                 public changeVolume(int ticks) {         volume.adjust(ticks);     }     public changeChannel(int channel, int ticks) {         if ( equalizer != null )             equalizer.getChannel(channel).adjust(ticks); }

Software example Models core elements of stereo: volume control, equalizer If statement: allows stereo without equalizer Problem: will need to check every use Violates a basic design principle: don’t repeat yourself Why is repetition a problem? How can we remove it? public class StereoController {     private Volume volume;     private Equalizer equalizer;     public StereoController(Volume volume, Equalizer equalizer) {         this.volume = volume;         this.equalizer = equalizer;     }                                 public changeVolume(int ticks) {         volume.adjust(ticks);     }     public changeChannel(int channel, int ticks) {         if ( equalizer != null )             equalizer.getChannel(channel).adjust(ticks); }

Solution: create “do nothing” classes public class Equalizer { public final int MAX_CHANNEL = 6; private Level[] channels = new Level[MAX_CHANNEL]; public Equalizer() { } public Level getChannel(int i) { return channels[i];     } } public class NullEqualizerObject extends Equalizer { private NullLevelObject nullLevel = new NullLevelObject(); return nullLevel; public class NullLevelObject extends Level { public adjust(int value) { } } NullEqualizerObject: returned channel does nothing on adjust

Removing the `if’ Stereo without equalizer: public class StereoController {     private Volume volume;     private Equalizer equalizer;     public StereoController(Volume volume, Equalizer equalizer) {         this.volume = volume;         this.equalizer = equalizer;     }                                 public changeVolume(int ticks) {         volume.adjust(ticks);     }     public changeChannel(int channel, int ticks) {         equalizer.getChannel(channel).adjust(ticks); } Removing the `if’ new StereoController(new Volume(), new NullEqualizerObject()); Stereo without equalizer:

Null Object Pattern Create a class that mirrors another Each operation “does nothing” Value returning operations: return something reasonable Use this class wherever might have a check for null Advantage: avoid lots of “if ( x != null )…” Disadvantage: more classes to write Clearly a bad idea in this case! Possibly useful for full Stereo Also: may delay raising an error: fail fast! Important details: Base class must be an interface – Null should have no unnecessary information Original class is listed as “RealClass” – don’t change this code because much of the system depends on it Do not be tempted to write messages or other side effects in the null A significant part of the course: identify problems and solve those problems using (design) patterns

SE-2811 Software Component Design CS-1020 6/6/2019 SE-2811 Software Component Design See syllabus at https://faculty-web.msoe.edu/hasker/se2811 Required: Optional: Print Dr. Mark L. Hornick

Review Design patterns: capturing frequent design solutions Reusing designs in addition to requirements, algorithms Null Object Pattern: avoiding if ( x == null )… through “do nothing” classes Next: Adapter Pattern