Design II Today: Design Principles…can we define them intro.12.ppt CS 121 “Ordering Chaos” “Mike” Michael A. Erlinger.

Slides:



Advertisements
Similar presentations
Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
Advertisements

Structured Design. 2 Design Quality – Simplicity “There are two ways of constructing a software design: One is to make it so simple that there are obviously.
K.I.S.S. Keep It Simple, Stupid! The Unix Philosophy in One Lesson* (*)
1 Software Design Introduction  The chapter will address the following questions:  How do you factor a program into manageable program modules that can.
Object-Oriented Application Development Using VB.NET 1 Chapter 5 Object-Oriented Analysis and Design.
Software Engineering Class design. Class design – ADT Abstract Data Types:  Why use ADT? Hidden implementation details Changes do not affect whole program.
Lecture 9 Improving Software Design CSC301-Winter 2011 – University of Toronto – Department of Computer Science Hesam C. Esfahani
What is Software Design?  Introduction  Software design consists of two components, modular design and packaging.  Modular design is the decomposition.
Copyright Irwin/McGraw-Hill Software Design Prepared by Kevin C. Dittman for Systems Analysis & Design Methods 4ed by J. L. Whitten & L. D. Bentley.
Testing and Inheritance What is the relation between the test suite of a superclass and a subclass?
OOAD Using the UML - Use-Case Analysis, v 4.2 Copyright  Rational Software, all rights reserved 1/18 Use Case Analysis – continued Control Classes.
API Design CPSC 315 – Programming Studio Fall 2008 Follows Kernighan and Pike, The Practice of Programming and Joshua Bloch’s Library-Centric Software.
Software Engineering and Design Principles Chapter 1.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
Chapter 1 Principles of Programming and Software Engineering.
Typing Issues and LSP David Rabinowitz. March 3rd, 2004 Object Oriented Design Course 2 Typing Static typing Reliability Catching errors early Readability.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
Software Issues Derived from Dr. Fawcett’s Slides Phil Pratt-Szeliga Fall 2009.
CSc 335: Three More OO Design Principles
13 Jul 2006CSE403, Summer'06, Lecture10 Lifecycle Architecture Review: Preliminary Feedback Valentin Razmov.
Chapter 7 Requirement Modeling : Flow, Behaviour, Patterns And WebApps.
CLASS DESIGN PRINCIPLES Lecture 2. The quality of the architecture What is a good design? It is the design that at least does not have signs of “bad”.
GENERAL CONCEPTS OF OOPS INTRODUCTION With rapidly changing world and highly competitive and versatile nature of industry, the operations are becoming.
1/19 Component Design On-demand Learning Series Software Engineering of Web Application - Principles of Good Component Design Hunan University, Software.
Object Oriented Analysis and Design Introduction.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
More Design. Next Tuesday First draft of architectural design –use cases –class diagrams for major classes with responsibilities –sequence diagrams for.
© 2004 Capgemini - All rights reserved SOLID - OO DESIGN PRINCIPLES Andreas Enbohm, Capgemini.
SE: CHAPTER 7 Writing The Program
Concepts of Software Quality Yonglei Tao 1. Software Quality Attributes  Reliability  correctness, completeness, consistency, robustness  Testability.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Chapter 7 Software Engineering Introduction to CS 1 st Semester, 2015 Sanghyun Park.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 6 Using Methods.
SWE © Solomon Seifu ELABORATION. SWE © Solomon Seifu Lesson 12-5 Software Engineering Design Goals.
GRASP: Designing Objects with Responsibilities
Coupling Cohesion Chandan R. Rupakheti Steve Chenoweth (Chapter 18)
Design.ppt1 Top-down designs: 1. Define the Problem IPO 2. Identify tasks, Modularize 3. Use structure chart 4. Pseudocode for Mainline 5. Construct pseudocode.
Chapter 10 Software Engineering. Understand the software life cycle. Describe the development process models. Understand the concept of modularity in.
1 Single Responsibility Principle Open Closed Principle Liskov Substitution Principle Law of Demeter CSC 335: Object-Oriented Programming and Design.
Software Design: Principles, Process, and Concepts Getting Started with Design.
1 Venkat Subramaniam Quality of Software Design Good design is critical to a software application A good design has following characteristics –Specific.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Software Engineering and Object-Oriented Design Topics: Solutions Modules Key Programming Issues Development Methods Object-Oriented Principles.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Object-Oriented Design. 1 Objects and concerns Objects have a concern, meaning they have a purpose Not concerned as in worried All code should have a.
Evaluating an Object-Oriented Design ©SoftMoore ConsultingSlide 1.
1. Perspectives on Design Principles – Semantic Invariants and Design Entropy Catalin Tudor 2.
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
Design. Practices Principles Patterns What are the characteristics of good design? What are good solutions to common design problems? How do we go about.
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
Duke CPS Programming Heuristics l Identify the aspects of your application that vary and separate them from what stays the same ä Take what varies.
SOFTWARE DESIGN & SOFTWARE ENGINEERING Software design is a process in which data, program structure, interface and their details are represented by well.
14 Jul 2005CSE403, Summer'05, Lecture 09 Lecture 09: Fundamental Principles and Best Practices for Software Design Valentin Razmov.
Principles of Programming & Software Engineering
Mantas Radzevičius ifm-2/2
GRASP – Designing Objects with Responsibilities
CompSci 280 S Introduction to Software Development
Object-Oriented Programming Concepts
Coupling and Cohesion Rajni Bhalla.
More Design Heuristics
Inheritance ITI1121 Nour El Kadri.
CMPE 135: Object-Oriented Analysis and Design October 24 Class Meeting
Principles of Programming and Software Engineering
About the Presentations
Programming Logic and Design Fourth Edition, Comprehensive
CMPE 135 Object-Oriented Analysis and Design March 21 Class Meeting
Designing For Testability
Object-Oriented PHP (1)
Presentation transcript:

Design II Today: Design Principles…can we define them intro.12.ppt CS 121 “Ordering Chaos” “Mike” Michael A. Erlinger

– 2 – CS 121 Design PracticesPrinciplesPatterns What are the characteristics of good design? What are good solutions to common design problems? How do we go about design and what do we produce? LAST TIME

– 3 – CS 121 Practices: Forms of Models Diagrams (UML) Text (hyperlinked) Prototypes Mathematical models Charts, graphs LAST TIME

– 4 – CS 121 Design PracticesPrinciplesPatterns What are the characteristics of good design? What are good solutions to common design problems? How do we go about design and what do we produce? TODAY: Principles of design Are there any? Do they matter? Can we evaluate them?

– 5 – CS 121 Goals at the Highest Level 1.Make it easy to build 2.Make it easy to test 3.Make it easy to maintain 4.Make it easy to change SIMPLE FLEXIBLE INTUITIVE

– 6 – CS 121 Mountains and molehills Design principles help manage the complexity that arises as project size grows. Software development in the: Small vs Large Problem is: Small grows to Large without a plan

– 7 – CS 121 Design Principle: DRY Don’t repeat yourself data/code should occur once and only once Examples: ?? SIMPLE, INTUITIVE, FLEXIBLE

– 8 – CS 121 Design Principle: Use real world objects INTUITIVE Domain model Design model Abstract: Game Real: Game console

– 9 – CS 121 Design Principle: SRP Single Responsibility Principle (SRP) every class/object should have a single responsibility SIMPLE, INTUITIVE, FLEXIBLE Several related principles Encapsulation, Abstraction, etc. Foundation of Software Development: Functions with single purpose, Objects, etc.

– 10 – CS 121 Design Principle: EV Encapsulate Variation every class should have only one reason to change FLEXIBLE Change should not cause a domino effect! related to SRP

– 11 – CS 121 EV example … Image processor bmp, Purpose: Convert images What happens when Input type changes?

– 12 – CS 121 EV example … Image processor bmp, Sometime Later: jpg, gif, … Image Loader bmp, Sometime Later: jpg, gif, …

– 13 – CS 121 Design Principle: HCLC High cohesion Low coupling related to SRP A class is cohesive if its data and methods are strongly connected Classes have low coupling if they are only loosely connected

– 14 – CS 121 Cohesion: Examples Functional cohesion (SRP): Coincidental cohesion: Logical cohesion: Temporal/sequential cohesion: Communicational: ?

– 15 – CS 121 Cohesion: Examples Functional cohesion (SRP): grouped because they contribute to a single well-defined task Coincidental cohesion: grouped together because Logical cohesion: grouped because they fall into some logical category, i.e. I/O Temporal/sequential cohesion: grouped because they are processed at the same time or in sequence; i.e. error handling (create log, notifies user, etc.) Communicational: grouped because they operate on same data, e.g., operate on same record BEST WORST

– 16 – CS 121 Coupling: Examples Content coupling: Common coupling: Control coupling: Data-structure coupling: Message coupling: ?

– 17 – CS 121 Coupling: Examples Content coupling: a module or class relies on the implementation of another; i.e. accessing private data Common coupling: modules or classes share global data Control coupling: one module controls the logic of another (e.g. passing a what-to-do flag) Data-structure coupling: modules share composite data structure Message coupling: modules communicate through interface BEST WORST

– 18 – CS 121 Design principle Law of Demeter Principle of Least Knowledge no no no: myGame->theBoard->cells[0][0].update() only talk to your friends

– 19 – CS 121 Design principle Law of Demeter no no no: myGame->theBoard->cells[0][0].update() Should not know details of theBoard only talk to your friends Each unit should have only limited knowledge about other units: only units "closely" related to the current unit. Each unit should only talk to its friends; don't talk to strangers. Only talk to your immediate friends. The fundamental notion is that a given object should assume as little as possible about the structure or properties of anything else (including its subcomponents).

– 20 – CS 121 Design Principle: Open-Closed principle classes should be open to extension but closed to modification architecture of your game

– 21 – CS 121 Design Principle: Open-Closed principle classes should be open to extension but closed to modification idea was that once completed, the implementation of a class could only be modified to correct errors; new or changed features would require that a different class be created architecture of your game

– 22 – CS 121 Composition and Inheritance ball sphere ball has a is a Design heuristic: Think like an object! shape is a

– 23 – CS 121 Design Principle A B A B inheritance composition has a isa Favor composition over inheritance BLACK box reuseWHITE box reuse

– 24 – CS 121 Design principle A B A B inheritance composition has a isa Favor composition over inheritance Caveat: sometime inheritance is the right thing (i.e. gives us polymorphism)

– 25 – CS 121 Design Principle: LSP B C isa Liskov substitution principle (LSP) void doSomething(B myThingOfTypeB) void doSomething(C myThingOfTypeC) this should work as well not just any banana

– 26 – CS 121 LSP violation rectangle square isa class Rectangle { public: void SetWidth(double w) {itsWidth=w;} void SetHeight(double h) {itsHeight=w;} double GetHeight() const {return itsHeight;} double GetWidth() const {return itsWidth;} private: double itsWidth; double itsHeight; }; some time later …

– 27 – CS 121 LSP violation rectangle square isa class Rectangle { public: void SetWidth(double w) {itsWidth=w;} void SetHeight(double h) {itsHeight=h;} double GetHeight() const {return itsHeight;} double GetWidth() const {return itsWidth;} private: double itsWidth; double itsHeight; }; void Square::SetWidth(double w) { Rectangle::SetWidth(w); Rectangle::SetHeight(w); } void Square::SetHeight(double h) { Rectangle::SetHeight(h); Rectangle::SetWidth(h); } PROBLEMS?

– 28 – CS 121 LSP: Assume a Square class that derives from a Rectangle class, assuming getter and setter methods exist for both width and height. The Square class always assumes that the width is equal with the height. If a Square object is used in a context where a Rectangle is expected, unexpected behavior may occur because the dimensions of a Square cannot (or rather should not) be modified independently. Assume a Square class that derives from a Rectangle class, assuming getter and setter methods exist for both width and height. The Square class always assumes that the width is equal with the height. If a Square object is used in a context where a Rectangle is expected, unexpected behavior may occur because the dimensions of a Square cannot (or rather should not) be modified independently. This problem cannot be easily fixed: if we can modify the setter methods in the Square class so that they preserve the Square invariant (i.e., keep the dimensions equal), then these methods will weaken (violate) the postconditions for the Rectangle setters, which state that dimensions can be modified independently. This problem cannot be easily fixed: if we can modify the setter methods in the Square class so that they preserve the Square invariant (i.e., keep the dimensions equal), then these methods will weaken (violate) the postconditions for the Rectangle setters, which state that dimensions can be modified independently.

– 29 – CS 121 LSP violation rectangle square isa class Rectangle { public: void SetWidth(double w) {itsWidth=w;} void SetHeight(double h) {itsHeight=w;} double GetHeight() const {return itsHeight;} double GetWidth() const {return itsWidth;} private: double itsWidth; double itsHeight; }; A square is not a rectangle!! Its external behavior is different

– 30 – CS 121 Design Principle INTUITIVE SIMPLE FLEXIBLE

– 31 – CS 121 Summary Don’t repeat yourself (D.R.Y) Use real world objects Single responsibility principle Encapsulate variation High cohesion/low coupling Program to an interface, not an implementation Law of Demeter (talk only to your friends) Favor composition over inheritance Open-closed principle Liskov Substitution Principle

– 32 – CS 121 Source: [Raymond, "Art of Unix Programming", Addison-Wesley, 2003] Rule of Modularity: Write simple parts connected by clean interfaces Rule of Clarity: Clarity is better than cleverness. Rule of Composition: Design programs to be connected to other programs. Rule of Separation: Separate policy from mechanism; separate interfaces from engines Rule of Simplicity: Design for simplicity; add complexity only where you must Rule of Parsimony: Write a big program only when it is clear by demonstration that nothing else will do Rule of Transparency: Design for visibility to make inspection and debugging easier Rule of Robustness: Robustness is the child of transparency and simplicity Rule of Representation: Fold knowledge into data so program logic can be stupid and robust Rule of Least Surprise: In interface design, always do the least surprising thing Rule of Silence: When a program has nothing surprising to say, it should say nothing Rule of Repair: When you must fail, fail noisily and as soon as possible Rule of Economy: Programmer time is expensive; conserve it in preference to machine time Rule of Generation: Avoid hand-hacking; write programs to write programs when you can Rule of Optimization: Prototype before polishing. Get it working before you optimize it Rule of Diversity: Distrust all claims for “one true way” Rule of Extensibility: Design for the future, because it will be here sooner than you think

– 33 – CS 121 Agile Design Philosophies Agile Designs are Emergent…Agile Designs are Emergent… Unit tests form detailed design doc WHEN do test-driven development (TDD)Unit tests form detailed design doc WHEN do test-driven development (TDD) Design models need to be just barely good enoughDesign models need to be just barely good enough Multiple models usedMultiple models used Use each model in multiple waysUse each model in multiple ways Designers should codeDesigners should code Prove it with codeProve it with code Feedback is your friend (team and/or outsiders)Feedback is your friend (team and/or outsiders) Iterate, iterate, iterateIterate, iterate, iterate Do design every dayDo design every day Document complicated thingsDocument complicated things Do not over document…until the endDo not over document…until the end

– 34 – CS 121 Agile Design Philosophies… Incorporate continuous User feedbackIncorporate continuous User feedback Understand your stakeholders…users, management, …Understand your stakeholders…users, management, … Design for the user experienceDesign for the user experience Make the app predictableMake the app predictable Bring objects to life through UIBring objects to life through UI

– 35 – CS 121 UNDER-PROMISE and OVER-DELIVER

– 36 – CS 121 The End

– 37 – CS 121 Trade offs Class A Class B Class C low cohesion high coupling