More Design. Next Tuesday First draft of architectural design –use cases –class diagrams for major classes with responsibilities –sequence diagrams for.

Slides:



Advertisements
Similar presentations
K.I.S.S. Keep It Simple, Stupid! The Unix Philosophy in One Lesson* (*)
Advertisements

Software Engineering Class design. Class design – ADT Abstract Data Types:  Why use ADT? Hidden implementation details Changes do not affect whole program.
General OO Concepts and Principles CSE301 University of Sunderland Harry R. Erwin, PhD.
SOLID Object Oriented Design Craig Berntson
5/17/2015 OO Design: Liskov Substitution Principle 1.
Error Management with Design Contracts Karlstad University Computer Science Error Management with Design Contracts Eivind J. Nordby, Martin Blom, Anna.
Testing and Inheritance What is the relation between the test suite of a superclass and a subclass?
Inheritance and object compatibility Object type compatibility An instance of a subclass can be used instead of an instance of the superclass, but not.
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.
More Inheritance and LSP CS340100, NTHU Yoshi. More about Inheritance Reuse? – Q1: 你有沒有程式 ” 砍掉重練 ” 的經驗 ? – Q2: 你有沒有 ” 再造輪子 ” 的經驗 ? class Rectangle – Firstly,
On the Relation between Design Contracts and Errors Karlstad University Computer Science On the Relation Between Design Contracts and Errors A Software.
Typing Issues and LSP Amit Shabtay. March 3rd, 2004 Object Oriented Design Course 2 Typing Static typing Readability (Java vs. Pearl) Catching errors.
NJIT More GRASP Patterns Chapter 22 Applying UML and Patterns Craig Larman Prepared By: Krishnendu Banerjee.
1 CS4850 Programming Languages Wuwei Shen. 2 Aministrivia Course home page: Reference books: –Programming Languages,
Feb. 23, 2004CS WPI1 CS 509 Design of Software Systems Lecture #5 Monday, Feb. 23, 2004.
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.
C Programming. C vs C++ C syntax and C++ syntax are the same but... C is not object oriented * There is no string class * There are no stream objects.
3/15/05H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)
CSCI-383 Object-Oriented Programming & Design Lecture 15.
CSc 335: Three More OO Design Principles
Design II Today: Design Principles…can we define them intro.12.ppt CS 121 “Ordering Chaos” “Mike” Michael A. Erlinger.
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”.
1/19 Component Design On-demand Learning Series Software Engineering of Web Application - Principles of Good Component Design Hunan University, Software.
1 OO Design Novosoft, 2001 by V. Mukhortov. 2 OO Design Goals  Flexibility Changes must be localized  Maintainability Modules requiring changes can.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
© 2004 Capgemini - All rights reserved SOLID - OO DESIGN PRINCIPLES Andreas Enbohm, Capgemini.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Key Principles of Software Architecture and Design (III) adapted from Dave Penny’s.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
1 Computer Science 340 Software Design & Testing Inheritance.
Design Principles iwongu at gmail dot com.
Software Design Principles
1 Single Responsibility Principle Open Closed Principle Liskov Substitution Principle Law of Demeter CSC 335: Object-Oriented Programming and Design.
Testing and Inheritance What is the relation between the test suite of a superclass and a subclass?
OO Design Principles Copyright © Vyacheslav Mukhortov, Nikita Nyanchuk-Tatarskiy, Copyright © INTEKS LLC,
Subtype Polymorphism, Subtyping vs
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Evaluating an Object-Oriented Design ©SoftMoore ConsultingSlide 1.
1. Perspectives on Design Principles – Semantic Invariants and Design Entropy Catalin Tudor 2.
Design. Practices Principles Patterns What are the characteristics of good design? What are good solutions to common design problems? How do we go about.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
CSSE501 Object-Oriented Development. Chapter 10: Subclasses and Subtypes  In this chapter we will explore the relationships between the two concepts.
Test Code Patterns How to design your test code. 2 Testing and Inheritance Should you retest inherited methods? Can you reuse superclass tests for inherited.
Object- oriented Design Principles
Duke CPS Programming Heuristics l Identify the aspects of your application that vary and separate them from what stays the same ä Take what varies.
The Law of Demeter For Operating System Course. Motivation Several programs were written in bad style Are difficult to maintain There is a simple remedy.
Subtype Polymorphism, Subtyping vs. Subclassing, Liskov Substitution Principle.
3/1/01H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)
Beginning Software Craftsmanship Brendan Enrick Steve Smith
CSCI 383 Object-Oriented Programming & Design Lecture 15 Martin van Bommel.
14 Jul 2005CSE403, Summer'05, Lecture 09 Lecture 09: Fundamental Principles and Best Practices for Software Design Valentin Razmov.
Mantas Radzevičius ifm-2/2
CompSci 280 S Introduction to Software Development
More Design Heuristics
Software Design Principles
Best Practices for Software System Design
CMPE 135: Object-Oriented Analysis and Design October 24 Class Meeting
Principles of Programming and Software Engineering
About the Presentations
CSE 331 Subtyping slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
object oriented Principles of software design
Software Design Principles
Subtype Polymorphism, Subtyping vs
Advanced Programming in Java
CMPE 135 Object-Oriented Analysis and Design March 21 Class Meeting
CMPE 135 Object-Oriented Analysis and Design March 7 Class Meeting
Liskov Substitution Principle (LSP)
Presentation transcript:

More Design

Next Tuesday First draft of architectural design –use cases –class diagrams for major classes with responsibilities –sequence diagrams for use cases –identify important algorithms and data structures and their parameters –critique with respect to good design principles

Next Tuesday First draft of architectural design Code/prototype Management update

Design Practices Principles Patterns 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: More Software design

Goals 1.Make it easy to build 2.Make it easy to test 3.Make it easy to maintain 4.Make it easy to change INTUITIVEFLEXIBLE

Summary Use real world objects Single responsibility principle Encapsulate change High cohesion/low coupling Open-closed principle Don’t repeat yourself (D.R.Y) Law of demeter (talk only to your friends)

Composition and Inheritance A B A B inheritance composition has a isa

Composition and Inheritance ball sphere ball inheritance composition has a isa “Think like an objective”

Composition and Inheritance ball sphere ball inheritance composition has a isa

Design Principle A B A B inheritance composition has a isa Favor composition over inheritance BLACK box reuseWHITE box reuse

Design Principle shape square shape square inheritance composition has a isa Favor composition over inheritance Caveat: sometime inheritance is the right thing (i.e. gives us polymorphism)

Bad design void DrawShape(const Shape& s) { if (typeid(s) == typeid(Square)) DrawSquare(static_cast (s)); else if (typeid(s) == typeid(Circle)) DrawCircle(static_cast (s)); } Shape SquareCircle

Design Principle B C isa Liskov substitution principle (LSP) void doSomething(B myThingOfTypeB) void doSomething(C myThingOfTypeC) this should work as well

Design Principle A B B C has a isa A C has a this should work too Liskov substitution principle (LSP)

shoe high heelsneaker I need shoes … not to mention feet

shoe high heelsneaker I need high heels

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 …

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?

void g(Rectangle& r) { r.SetWidth(5); r.SetHeight(4); assert(r.GetWidth() * r.GetHeight()) == 20); }

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

Design by contract A virtual doSomething() pre-conditions post-conditions LSP: If B’s pre-conditions is different than A’s, it must be weaker. If B’s post-condition is different than A’s, it must be stronger. isa B doSomething() pre-conditions post-conditions

Design Principle INTUITIVE FLEXIBle

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

UNDER-PROMISE and OVER-DELIVER

Choose 5 design principles (from last time or today) Critique your current domain/design model