Common mistakes Basic Design Principles David Rabinowitz.

Slides:



Advertisements
Similar presentations
Object Oriented Programming with Java
Advertisements

CS 350 – Software Design The Bridge Pattern – Chapter 10 Most powerful pattern so far. Gang of Four Definition: Decouple an abstraction from its implementation.
Chapter 14 Graph class design John Keyser’s Modifications of Slides by Bjarne Stroustrup
1 Object-Oriented Reengineering © R. Marinescu Lecture 5 Radu Marinescu Principles of Object-Oriented Design.
Inheritance. 2 Inheritance allows a software developer to derive a new class from an existing one The existing class is called the parent class or superclass.
CSCI 143 OOP – Inheritance 1. What is Inheritance? A form of software reuse Create a new class from an existing class – Absorb existing class data and.
R R R CSE870: Advanced Software Engineering: Frameworks (Cheng, Sp2003)1 Frameworks A Brief Introduction.
Common mistakes Basic Design Principles Amit Shabtay.
Developed by Reneta Barneva, SUNY Fredonia Component Level Design.
13 Jul 2006CSE403, Summer'06, Lecture10 Lifecycle Architecture Review: Preliminary Feedback Valentin Razmov.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Advanced Principles I Principles of Object-Oriented Class Design Copyright  by Object Mentor, Inc All Rights Reserved Portions of this material.
Design Dan Fleck CS 421 George Mason University. What is the design phase? Analysis phase describes what the system should do Analysis has provided a.
1 OO Design Novosoft, 2001 by V. Mukhortov. 2 OO Design Goals  Flexibility Changes must be localized  Maintainability Modules requiring changes can.
CS 325: Software Engineering March 17, 2015 Applying Patterns (Part A) The Façade Pattern The Adapter Pattern Interfaces & Implementations The Strategy.
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
Principles of Object-Oriented Design SEI, SJTU WEB APPS and SERVICES.
Tech Talk Go4 Factory Patterns Presented By: Matt Wilson.
© 2004 Capgemini - All rights reserved SOLID - OO DESIGN PRINCIPLES Andreas Enbohm, Capgemini.
S.O.L.I.D. Software Development 12 January 2010 (Martin Verboon, Patrick Kalkman, Stan Verdiesen)
CPSC 372 John D. McGregor Module 4 Session 1 Design Patterns.
SWE © Solomon Seifu ELABORATION. SWE © Solomon Seifu Lesson 12-5 Software Engineering Design Goals.
Design Principles iwongu at gmail dot com.
The benefits of SOLID in software development Ruben Agudo Santos (GS-AIS-HR)
Frameworks & Patterns Use of Organized Classes. Frameworks vs Toolkits Framework Framework  Start with classes and interfaces that define a rudimentary.
Peyman Dodangeh Sharif University of Technology Fall 2014.
Structural Pattern: Bridge When the abstract interface and the concrete implementation have been set up as parallel class hierarchies, it becomes difficult.
Software Design Principles
Incremental Design Why incremental design? Goal of incremental design Tools for incremental design  UML diagrams  Design principles  Design patterns.
OO Design Principles Copyright © Vyacheslav Mukhortov, Nikita Nyanchuk-Tatarskiy, Copyright © INTEKS LLC,
CPSC 871 John D. McGregor Module 5 Session 1 Design Patterns.
Abstraction ADTs, Information Hiding and Encapsulation.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
High Cohesion Low Coupling Old Standards for Object Oriented Programming.
Lecture Notes – Inheritance and Polymorphism (Ch 9-10) Yonglei Tao.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
1 Design by Principles (Robert Martin) Software Engineering.
Evaluating an Object-Oriented Design ©SoftMoore ConsultingSlide 1.
Principles of Object Oriented Design
PRINCIPLES OF OBJECT ORIENTED DESIGN S.O.L.I.D. S.O.L.I.D Principles What is SOLID?  Acrostic of 5 Principles:  The Single Responsibility Principle.
Component Design Elaborating the Design Model. Component Design Translation of the architectural design into a detailed (class-based or module- based)
SOLID Design Principles
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
S.Ducasse Stéphane Ducasse 1 Some Principles Stéphane Ducasse ---
1 Good Object-Oriented Design Radu Marinescu Lecture 3 Principles of Object-Oriented Design Part II 19 th November 2002.
NCCUCS Software Engineering 補充投影片 April 14, 2014.
14 Jul 2005CSE403, Summer'05, Lecture 09 Lecture 09: Fundamental Principles and Best Practices for Software Design Valentin Razmov.
1 Advanced Object- oriented Design – Principles CS320 Fall 2005.
Appendix 1 - Packages Jim Fawcett copyright (c)
Course information Old exam Resit Report Result and walkthrough
More Design Heuristics
Inheritance ITI1121 Nour El Kadri.
Design Points - Law of Demeter
Copyright © by Curt Hill
Review: Two Programming Paradigms
null, true, and false are also reserved.
lecture 08, OO Design Principle
Subtype Polymorphism, Subtyping vs
Design Tips.
Questions First On class? On project? On material we’ve discussed?
Objects First with Java A Practical Introduction using BlueJ
Principles of Object-Oriented Design
The SOLID Principles.
Objects First with Java A Practical Introduction using BlueJ
Principles of Object-Oriented Design Part II
Principles of Object-Oriented Design
Object Oriented Design & Analysis
Some principles for object oriented design
Notes on software design
Chapter 10 – Component-Level Design
Presentation transcript:

Common mistakes Basic Design Principles David Rabinowitz

March 3rd, 2004 Object Oriented Design Course 2 Common Mistakes Repeated often Especially with the inexperienced Don’t you make them! How to recognize the danger signals?

March 3rd, 2004 Object Oriented Design Course 3 Danger Signals (1) public class Counter { public int howManyA(String s) { int conut = 0; for(int i = 0; i < s.length(); ++i) if(s.charAt(i) == 'a') ++count; return count; } } Is this a class?

March 3rd, 2004 Object Oriented Design Course 4 Danger Signals (2) Class City extends Place { … } Class Jerusalem extends City implements Capital { … } Class TelAviv extends City { … } What is wrong here?

March 3rd, 2004 Object Oriented Design Course 5 Danger Signals (3) Class Person { String getName(); void setName(String name); int getAge(); void setAge(int age); Car getCar(); void setCar(Car car); } What do we see ?

March 3rd, 2004 Object Oriented Design Course 6 Basic Design Principles (abridged) The Open Closed Principle The Dependency Inversion Principle The Interface Segregation Principle The Acyclic Dependencies Principle

March 3rd, 2004 Object Oriented Design Course 7 The Open Closed Principle Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification. In the OO way: A class should be open for extension, but closed for modification. Existing code should not be changed – new features can be added using inheritance or composition.

March 3rd, 2004 Object Oriented Design Course 8 Example enum ShapeType {circle, square}; struct Shape { ShapeType _type; }; struct Circle { ShapeType _type; double _radius; Point _center; }; struct Square { ShapeType _type; double _side; Point _topLeft; }; void DrawSquare(struct Square*) void DrawCircle(struct Circle*);

March 3rd, 2004 Object Oriented Design Course 9 Example (cont.) void DrawAllShapes(struct Shape* list[], int n) { int i; for (i=0; i<n; i++) { struct Shape* s = list[i]; switch (s->_type) { case square: DrawSquare((struct Square*)s); break; case circle: DrawCircle((struct Circle*)s); break; } Where is the violation?

March 3rd, 2004 Object Oriented Design Course 10 Correct Form class Shape { public: virtual void Draw() const = 0; }; class Square : public Shape { public: virtual void Draw() const; }; class Circle : public Shape { public: virtual void Draw() const; }; void DrawAllShapes(Set & list) { for (Iterator i(list); i; i++) (*i)->Draw();

March 3rd, 2004 Object Oriented Design Course 11 The Dependency Inversion Principle A. High level modules should not depend upon low level modules. Both should depend upon abstractions. B. Abstractions should not depend upon details. Details should depend upon abstractions.

March 3rd, 2004 Object Oriented Design Course 12 Example void Copy() { int c; while ((c = ReadKeyboard()) != EOF) WritePrinter(c); } Where is the violation?

March 3rd, 2004 Object Oriented Design Course 13 Example (cont.) Now we have a second writing device – disk enum OutputDevice {printer, disk}; void Copy(outputDevice dev) { int c; while ((c = ReadKeyboard()) != EOF) if (dev == printer) WritePrinter(c); else WriteDisk(c); }

March 3rd, 2004 Object Oriented Design Course 14 Correct form class Reader { public: virtual int Read() = 0; }; class Writer { public: virtual void Write(char)=0; }; void Copy(Reader& r, Writer& w) { int c; while((c=r.Read()) != EOF) w.Write(c); }

March 3rd, 2004 Object Oriented Design Course 15 The Interface Segregation Principle The dependency of one class to another one should depend on the smallest possible interface. Avoid “fat” interfaces

March 3rd, 2004 Object Oriented Design Course 16 The Interface Segregation Principle

March 3rd, 2004 Object Oriented Design Course 17 The Interface Segregation Principle

March 3rd, 2004 Object Oriented Design Course 18 Example class Door { public: virtual void Lock() = 0; virtual void Unlock() = 0; virtual bool IsDoorOpen() = 0; }; class Timer { public: void Regsiter(int timeout, TimerClient* client); }; class TimerClient { public: virtual void TimeOut() = 0; };

March 3rd, 2004 Object Oriented Design Course 19 A Timed Door

March 3rd, 2004 Object Oriented Design Course 20 Correct Form Two options: Adapter Multiple Inheiritence

March 3rd, 2004 Object Oriented Design Course 21 The Acyclic Dependencies Principle The dependency structure between packages must not contain cyclic dependencies.

March 3rd, 2004 Object Oriented Design Course 22 Example

March 3rd, 2004 Object Oriented Design Course 23 Correct Form

March 3rd, 2004 Object Oriented Design Course 24 Example 2

March 3rd, 2004 Object Oriented Design Course 25 The Law Of Demeter Only talk to your immediate friends. In other words: You can play with yourself. ( this.method() ) You can play with your own toys (but you can't take them apart). ( field.method(), field.getX() ) You can play with toys that were given to you. ( arg.method() ) And you can play with toys you've made yourself. ( A a = new A(); a.method() )

March 3rd, 2004 Object Oriented Design Course 26 Example

March 3rd, 2004 Object Oriented Design Course 27 How to correct

March 3rd, 2004 Object Oriented Design Course 28 Example Code

March 3rd, 2004 Object Oriented Design Course 29 Resources Our resources page resources/articleIndex Don’t be afraid from “old” articles

March 3rd, 2004 Object Oriented Design Course 30 Package cohesion The Common Closure Principle Classes within a released component should share common closure. That is, if one needs to be changed, they all are likely to need to be changed. The Common Reuse Principle The classes in a package are reused together. If you reuse one of the classes in a package, you reuse them all.