SlideShare a Scribd company logo
Object Oriented Design Sudarsun S.,  M.Tech Director – R & D Checktronix India Pvt Ltd Chennai 600010
Objectives ,[object Object],[object Object],[object Object]
What is an OBJECT ,[object Object],[object Object],[object Object],[object Object],[object Object]
A little Quiz… ,[object Object],Dog is a generalization of Scooby-Doo Dog Scooby-Doo
A little Quiz (cont’d)… ,[object Object],The concept of  subclass ! Dog is a subclass of the Animal class Animal is a generalization of Dog Dog Scooby-Doo Animal
A little Quiz (cont’d)… ,[object Object],The concept of  polymorphism ! Animal Dog Bird
Characteristics of OOD ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Interacting objects
Advantages of OOD ,[object Object],[object Object],[object Object]
Object-oriented development ,[object Object],[object Object],[object Object],[object Object]
Objects and object classes  ,[object Object],[object Object],[object Object],[object Object]
Object communication ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Message examples ,[object Object],[object Object],[object Object],[object Object]
Generalisation and inheritance ,[object Object],[object Object],[object Object],[object Object],[object Object]
A generalisation hierarchy
Object Relationships ,[object Object],[object Object],[object Object]
Object identification ,[object Object],[object Object],[object Object],[object Object],[object Object]
Approaches to identification ,[object Object],[object Object],[object Object],[object Object]
Object interface specification ,[object Object],[object Object],[object Object]
Examples of design models ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Weather station subsystems
Weather station - data collection sequence
State charts ,[object Object],[object Object]
OO Design Process –  Access Layer ,[object Object],[object Object],[object Object],[object Object]
Object Oriented Design Process ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example: Invoice
Example: Invoice ,[object Object],[object Object],[object Object],[object Object]
Finding Classes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CRC Card ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CRC Card
Self Check ,[object Object],[object Object],[object Object]
Answers ,[object Object],[object Object],[object Object]
Relationships Between Classes ,[object Object],[object Object],[object Object]
Inheritance ,[object Object],[object Object],[object Object],Continued…
Inheritance ,[object Object],[object Object],[object Object],[object Object]
Aggregation ,[object Object],[object Object],[object Object],[object Object],[object Object],class Tire {   . . .   private String rating;   private Circle boundary; }
Example class Car extends Vehicle {   . . .   private Tire[] tires; }
Example UML Notation for Inheritance and Aggregation
Dependency ,[object Object],[object Object],[object Object],[object Object]
UML Relationship Symbols Open Dotted  Dependency Diamond Solid Aggregation Triangle Dotted Interface Implementation Triangle Solid Inheritance Arrow Tip Line Style Symbol Relationship
Self Check ,[object Object],[object Object],[object Object]
Answers ,[object Object],[object Object],[object Object]
Attributes and Methods in UML Attributes and Methods in a Class Diagram
Multiplicities ,[object Object],[object Object],[object Object],[object Object],An Aggregation Relationship with Multiplicities
Aggregation and Association ,[object Object],[object Object],[object Object],[object Object],Continued…
Aggregation and Association An Association Relationship
Five-Part Development Process ,[object Object],[object Object],[object Object],[object Object],[object Object]
Printing an Invoice – Requirements ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Continued…
Sample Invoice
CRC Cards ,[object Object],[object Object],Invoice Address LineItem Product Description Price Quantity Total Amount Due
CRC Cards ,[object Object],Invoice Address LineItem  // Records the product and the quantity Product Description // Field of the Product class Price  // Field of the Product class Quantity  // Not an attribute of a Product Total  // Computed–not stored anywhere Amount Due  // Computed–not stored anywhere  Continued…
CRC Cards ,[object Object],Invoice Address LineItem Product
CRC Cards for Printing Invoice ,[object Object]
CRC Cards for Printing Invoice ,[object Object]
CRC Cards for Printing Invoice ,[object Object]
CRC Cards for Printing Invoice ,[object Object]
Printing an Invoice – UML Diagrams The Relationships Between the Invoice Classes
Method Documentation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Method Documentation –  Invoice  class  /**   Describes an invoice for a set of purchased products. */ public class Invoice {   /**   Adds a charge for a product to this invoice.   @param aProduct the product that the customer ordered   @param quantity the quantity of the product   */   public void add(Product aProduct, int quantity)   {   }   /**   Formats the invoice.   @return the formatted invoice   */   public String format()   {   } }
Method Documentation –  LineItem  class  /**   Describes a quantity of an article to purchase and its price. */ public class LineItem {   /**   Computes the total cost of this line item.   @return the total price   */   public double getTotalPrice()   {   }   /**   Formats this item.   @return a formatted string of this line item   */   public String format()   {   } }
Method Documentation –  Product  class  /**   Describes a product with a description and a price. */ public class Product {   /**   Gets the product description.   @return the description   */   public String getDescription()   {   }   /**   Gets the product price.   @return the unit price   */   public double getPrice()   {   } }
Method Documentation –  Address  class  /**   Describes a mailing address. */ public class Address {   /**   Formats the address.   @return the address as a string with three lines   */   public String format()   {   } }
Implementation ,[object Object],[object Object],[object Object],public class Invoice {   . . .   private Address billingAddress;   private ArrayList<LineItem> items; }
Implementation ,[object Object],public class LineItem {   . . .   private int quantity;   private Product theProduct; }
Implementation ,[object Object],[object Object],[object Object],/**   Computes the total cost of this line item.   @return the total price */ public double getTotalPrice() {   return theProduct.getPrice() * quantity; }
Self Check ,[object Object],[object Object]
Answers ,[object Object],[object Object]
Suh’s Axioms of OOD ,[object Object],[object Object]
Occum’s Razor rule of simplicity ,[object Object],[object Object],[object Object]
Some Corollaries… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Uncoupled Design ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Cohesion ,[object Object],[object Object],[object Object],[object Object],[object Object]
Corollary 2:  Single Purpose  ,[object Object],[object Object],[object Object],[object Object],[object Object]
Achieving Multiple Inheritance ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Class Visibility ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Design patterns ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Pattern elements ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Types of Patterns ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Patterns by Example: Multiple displays enabled by Observer A=10% B=40% C=30% D=20% Application data A B C D A D C B Relative Percentages Y 10  40  30 20 X 15  35  35 15 Z 10  40  30 20 A  B  C  D Change notification Requests, modifications
The Observer pattern ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The Observer pattern observerState= subject     getState(); Subject attach (Observer) detach (Observer) Notify () Observer Update() Concrete Observer Update() observerState Concrete Subject GetState() SetState() subjectState observers subject For all x in observers{ x     Update(); }
The Mediator Pattern ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The Mediator Pattern
The Façade Pattern ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Facade   Pattern: Problem Subsystem classes Client Classes Need to communicate with
Facade   Pattern: Solution Subsystem classes Fac ade Client Classes
The Façade Pattern
The Proxy Pattern ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The Proxy Pattern
The Adapter Pattern ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The Adapter Pattern
The Abstract Factory Pattern ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The Abstract Factory Pattern AbstractFactory CreateProductA() CreateProductB() ConcreteFactory1 Client ProductA1 ProductA2 AbstractProductA ProductB2 ProductB1 AbstractProductB ConcreteFactory2 CreateProductA() CreateProductB()
Abstract Factory Example WidgetFactory CreateScrollbar() CreateWindow() Window ScrollBar WWidgetFactory MacWidgetFactory Client WWindow MacWindow MacScrollBar WScrollBar One for each standard.
[object Object],[object Object],[object Object],[object Object],Dependency Management
What is dependency management? ,[object Object],[object Object]
What bearing does DM have on software? ,[object Object],[object Object]
What is the penalty for practicing poor DM? ,[object Object],[object Object],[object Object],[object Object],A system with poor dependency structure will typically exhibit these four negative traits:
It is Rigid ,[object Object],[object Object],[object Object],[object Object],[object Object],Rigidity is the inability  to be changed
Changes with Rigidity The System Officially Rigid Area Where the change should be made Where the change must be made now Are we containing risk, or spreading rot?
It is Fragile ,[object Object],[object Object],[object Object],[object Object],Software changes seem to exhibit non-local effects
Increasing Risk Defects v. Cumulative Modifications Systems tend to become increasingly fragile over time. Intentional, planned partial rewrites may be necessary to sustain growth and maintenance. Changes Probability of  introducing a bug 1.0
It is not reusable ,[object Object],[object Object]
The Trailer The Trailer
It has high viscosity ,[object Object],[object Object],Viscosity is resistance to fluid motion.
What is the benefit  of good DM? Interdependencies are managed, with firewalls separating aspects that need to vary independently. Fewer Trailers Slow the rot More Flexible Less fragile, the bugs are boxed in Easier to reuse Easier to make the right change
What causes “Code Rot”? ,[object Object],It’s been blamed on stupidity, lack of discipline, and phases of the moon, but...
First Version All designs start well The program is an overnight success! How could it be more simple, elegant, and maintainable? void copy(void) { int ch; while( (ch=ReadKeyboard()) != EOF) WritePrinter(ch); }
Second Version ,[object Object],[object Object],[object Object],Oh, no! Nobody said the requirements might change!
Second Version Design bool GtapeReader = false; // remember to clear void copy(void) { int ch; while( (ch=GtapeReader ? ReadTape() : ReadKeyboard()) != EOF) WritePrinter(ch); }
Third Version How unexpected! Requirements changed again! bool GtapeReader = false;  Bool GtapePunch = false;  // remember to clear void copy(void) { int ch; while( (ch=GtapeReader ? ReadTape() : ReadKeyboard()) != EOF) GtapePunch ? WritePunch(ch) : WritePrinter(ch); } It seems that sometimes we need to write to a paper tape punch. We’ve had this problem before, and just added a flag. Looks like it should work again.
Example of a Good Design First and only version. void Copy() { int c; while( (c=getchar()) != EOF) putchar(c); } But wait! Aren’t we supposed to be learning OO design? This isn’t OO is it?
… is it? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],It is a small program based on abstractions! FILE is a class, just implemented differently.
Rephrased in OO interface Reader { char read(); } interface Writer { void write(char c); } public class Copy { Copy(Reader r, Writer w) { itsReader = r; itsWriter = w; } public void copy() { int c; while( (c==itsReader.read()) != EOF ) itsWriter.write(c); } private Reader itsReader; private Writer  itsWriter; }
Class Design Principles ,[object Object],[object Object],[object Object],[object Object],[object Object],From: Agile Software Development: Principles, Patterns, and Practices. Robert C. Martin, Prentice Hall, 2002.
The Single Responsibility Principle ,[object Object]
Open/Closed Principle ,[object Object],[object Object],[object Object],“ Modules should be open for extension, but closed for modification” -Bertrand Meyer
Abstraction is Key ,[object Object],[object Object],[object Object],Abstraction is  the most important   word in OOD
The Shape Example ,[object Object],[object Object]
Procedural (open) version enum ShapeType {circle, square}; struct Shape  {enum ShapeType itsType;}; struct Circle  { enum ShapeType itsType; double itsRadius; Point itsCenter; }; void DrawCircle(struct Circle*) struct Square  { enum ShapeType itsType; double itsSide; Point itsTopLeft; }; void DrawSquare(struct Square*) #include <Shape.h> #include <Circle.h> #include <Square.h> typedef struct Shape* ShapePtr; void  DrawAllShapes(ShapePtr list[], int n) { int i; for( i=0; i< n, i++ ) { ShapePtr s = list[i]; switch ( s->itsType ) { case square: DrawSquare((struct Square*)s); break; case circle: DrawCircle((struct Circle*)s); break; } } } Shape.h Circle.h Square.h DrawAllShapes.c
What is wrong with the code? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],It can be demonstrated to work. Isn’t that the important thing?
A Closed Implementation Class Shape { public: virtual void Draw() const =0; }; #include <Shape.h> void  DrawAllShapes(Shape* list[],int n) { for(int i=0; i< n; i++) list[i]->draw(); } Shape.h DrawAllShapes.cpp Circle.h Square.h Class Square: public Shape { public: virtual void Draw() const; }; Class Circle: public Shape { public: virtual void Draw() const; };
Strategic Closure ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],No program is 100% closed.
Liskov Substitution Principle ,[object Object],[object Object],Derived classes must be usable through the base class interface, without the need for the user to know the difference.
Square/Rectangle A square is-a rectangle, right? So lets consider Square as a subtype of Rectangle. void Square::SetWidth(double w) { width = w; height = w; } void Square::SetHeight(double h) { width = h; height = h; } We can  make  it work: Uh, oh. This doesn’t quite seem to fit
Substitution… denied! ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Liskov Substitution Principle ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Liskov Substitution Principle ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Design by Contract ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],int Base::f(int x); // REQUIRE: x is odd // PROMISE: return even int int Derived::f(int x); // REQUIRE: x is int // PROMISE: return 8
LSP is about Semantics and Replacement ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Dependency Inversion Principle Details should depend on abstractions. Abstractions should not depend on details. V.
Dependency Inversion Principle I.  High-level modules should  not   depend on low-level modules.  Both should depend on abstractions. II. Abstractions should not depend on details.  Details should depend on abstractions R. Martin , 1996  ,[object Object],[object Object],[object Object]
Procedural vs. OO Architecture Procedural  Architecture Object-Oriented  Architecture
DIP Applied on Example Copy Reader Writer Keyboard Reader Printer Writer class Reader { public:  virtual int read()=0; }; class Writer { public:  virtual void write(int)=0; }; void Copy(Reader& r, Writer& w){ int c; while((c = r.read()) != EOF) w.write(c); } Disk Writer
Interface Segregation Principle ,[object Object],[object Object],[object Object],[object Object],[object Object],Helps deal with “fat” or inappropriate interfaces
Interface Pollution by “collection” Distinct clients of our class have distinct interface needs.
A Segregated Example
ATM UI Example
A Segregated ATM UI Example
Logger Example
Four Class Design Principles - Review ,[object Object],[object Object],[object Object],[object Object]
Thank you ,[object Object],[object Object],[object Object]

More Related Content

What's hot

L ab # 07
L ab # 07L ab # 07
L ab # 07Mr SMAK
 
Bt8901 objective oriented systems1
Bt8901 objective oriented systems1Bt8901 objective oriented systems1
Bt8901 objective oriented systems1
Techglyphs
 
Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UML
yndaravind
 
classes & objects introduction
classes & objects introductionclasses & objects introduction
classes & objects introduction
Kumar
 
Lecture#01, object orientation
Lecture#01, object orientationLecture#01, object orientation
Lecture#01, object orientationbabak danyal
 
Object Oriented Concept
Object Oriented ConceptObject Oriented Concept
Object Oriented Conceptsmj
 
Classes and Objects
Classes and Objects  Classes and Objects
Classes and Objects
yndaravind
 
Class diagram
Class diagramClass diagram
Class diagram
SESP123
 
Vb ch 3-object-oriented_fundamentals_in_vb.net
Vb ch 3-object-oriented_fundamentals_in_vb.netVb ch 3-object-oriented_fundamentals_in_vb.net
Vb ch 3-object-oriented_fundamentals_in_vb.net
bantamlak dejene
 
Interfaces & Packages V2
Interfaces & Packages V2Interfaces & Packages V2
Interfaces & Packages V2
Dr Anjan Krishnamurthy
 
Lecture 1 uml with java implementation
Lecture 1 uml with java implementationLecture 1 uml with java implementation
Lecture 1 uml with java implementationthe_wumberlog
 
Object analysis and design
Object analysis and designObject analysis and design
Object analysis and designAnand Grewal
 
Synapseindia strcture of dotnet development part 1
Synapseindia strcture of dotnet development part 1Synapseindia strcture of dotnet development part 1
Synapseindia strcture of dotnet development part 1
Synapseindiappsdevelopment
 
Unit 2
Unit 2Unit 2
Software Engineering :UML class diagrams
Software Engineering :UML class diagramsSoftware Engineering :UML class diagrams
Software Engineering :UML class diagrams
Ajit Nayak
 
Chapter 6.4
Chapter 6.4Chapter 6.4
Chapter 6.4sotlsoc
 
OOP Concepets and UML Class Diagrams
OOP Concepets and UML Class DiagramsOOP Concepets and UML Class Diagrams
OOP Concepets and UML Class Diagrams
Bhathiya Nuwan
 

What's hot (20)

Ooad
OoadOoad
Ooad
 
L ab # 07
L ab # 07L ab # 07
L ab # 07
 
Bt8901 objective oriented systems1
Bt8901 objective oriented systems1Bt8901 objective oriented systems1
Bt8901 objective oriented systems1
 
Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UML
 
classes & objects introduction
classes & objects introductionclasses & objects introduction
classes & objects introduction
 
Lecture#01, object orientation
Lecture#01, object orientationLecture#01, object orientation
Lecture#01, object orientation
 
Object Oriented Concept
Object Oriented ConceptObject Oriented Concept
Object Oriented Concept
 
Classes and Objects
Classes and Objects  Classes and Objects
Classes and Objects
 
Class diagram
Class diagramClass diagram
Class diagram
 
Vb ch 3-object-oriented_fundamentals_in_vb.net
Vb ch 3-object-oriented_fundamentals_in_vb.netVb ch 3-object-oriented_fundamentals_in_vb.net
Vb ch 3-object-oriented_fundamentals_in_vb.net
 
Interfaces & Packages V2
Interfaces & Packages V2Interfaces & Packages V2
Interfaces & Packages V2
 
Lecture 1 uml with java implementation
Lecture 1 uml with java implementationLecture 1 uml with java implementation
Lecture 1 uml with java implementation
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Object analysis and design
Object analysis and designObject analysis and design
Object analysis and design
 
Synapseindia strcture of dotnet development part 1
Synapseindia strcture of dotnet development part 1Synapseindia strcture of dotnet development part 1
Synapseindia strcture of dotnet development part 1
 
Classes2
Classes2Classes2
Classes2
 
Unit 2
Unit 2Unit 2
Unit 2
 
Software Engineering :UML class diagrams
Software Engineering :UML class diagramsSoftware Engineering :UML class diagrams
Software Engineering :UML class diagrams
 
Chapter 6.4
Chapter 6.4Chapter 6.4
Chapter 6.4
 
OOP Concepets and UML Class Diagrams
OOP Concepets and UML Class DiagramsOOP Concepets and UML Class Diagrams
OOP Concepets and UML Class Diagrams
 

Viewers also liked

Webcast Scanning Updated Version 1.0.6
Webcast Scanning Updated Version 1.0.6Webcast Scanning Updated Version 1.0.6
Webcast Scanning Updated Version 1.0.6
medtimer
 
Animals
AnimalsAnimals
Animals
Mar Mendoza
 
What It Takes To Be The Best It Trainer?
What It Takes To Be The Best It Trainer?What It Takes To Be The Best It Trainer?
What It Takes To Be The Best It Trainer?Aravinth NSP
 
Collage report on Online trading
Collage report on Online tradingCollage report on Online trading
Collage report on Online trading
rai_rohit
 
PBGH Symposium 2012 Presentation Kresse
PBGH Symposium 2012 Presentation KressePBGH Symposium 2012 Presentation Kresse
PBGH Symposium 2012 Presentation Kresse
markkresse
 
Amer College of Cardiovascular Administrators March 2004
Amer College of Cardiovascular Administrators March 2004Amer College of Cardiovascular Administrators March 2004
Amer College of Cardiovascular Administrators March 2004
markkresse
 
Mutual funds is the better investments plan
Mutual funds is the better investments planMutual funds is the better investments plan
Mutual funds is the better investments plan
Projects Kart
 
Online Stock Trading
Online Stock TradingOnline Stock Trading
Online Stock Trading
arfatrulz
 
Sharekhan project report ,mba
Sharekhan  project report ,mbaSharekhan  project report ,mba
Sharekhan project report ,mba
Shoyal Akhtar
 
33059297 a-project-report-on-online-trading-stock-brokers-of-sharekhan
33059297 a-project-report-on-online-trading-stock-brokers-of-sharekhan33059297 a-project-report-on-online-trading-stock-brokers-of-sharekhan
33059297 a-project-report-on-online-trading-stock-brokers-of-sharekhanRam Agrawal
 
A project report on online trading
A project report on online tradingA project report on online trading
A project report on online tradingKumar Gaurav
 

Viewers also liked (13)

MediaFilmExchange.co.uk Powerpoint
MediaFilmExchange.co.uk PowerpointMediaFilmExchange.co.uk Powerpoint
MediaFilmExchange.co.uk Powerpoint
 
Webcast Scanning Updated Version 1.0.6
Webcast Scanning Updated Version 1.0.6Webcast Scanning Updated Version 1.0.6
Webcast Scanning Updated Version 1.0.6
 
Animals
AnimalsAnimals
Animals
 
What It Takes To Be The Best It Trainer?
What It Takes To Be The Best It Trainer?What It Takes To Be The Best It Trainer?
What It Takes To Be The Best It Trainer?
 
Collage report on Online trading
Collage report on Online tradingCollage report on Online trading
Collage report on Online trading
 
PBGH Symposium 2012 Presentation Kresse
PBGH Symposium 2012 Presentation KressePBGH Symposium 2012 Presentation Kresse
PBGH Symposium 2012 Presentation Kresse
 
Amer College of Cardiovascular Administrators March 2004
Amer College of Cardiovascular Administrators March 2004Amer College of Cardiovascular Administrators March 2004
Amer College of Cardiovascular Administrators March 2004
 
Mutual funds is the better investments plan
Mutual funds is the better investments planMutual funds is the better investments plan
Mutual funds is the better investments plan
 
Online trading
Online tradingOnline trading
Online trading
 
Online Stock Trading
Online Stock TradingOnline Stock Trading
Online Stock Trading
 
Sharekhan project report ,mba
Sharekhan  project report ,mbaSharekhan  project report ,mba
Sharekhan project report ,mba
 
33059297 a-project-report-on-online-trading-stock-brokers-of-sharekhan
33059297 a-project-report-on-online-trading-stock-brokers-of-sharekhan33059297 a-project-report-on-online-trading-stock-brokers-of-sharekhan
33059297 a-project-report-on-online-trading-stock-brokers-of-sharekhan
 
A project report on online trading
A project report on online tradingA project report on online trading
A project report on online trading
 

Similar to Object Oriented Design

UNIT II STATIC UML DIAGRAMS.pptx
UNIT II STATIC UML DIAGRAMS.pptxUNIT II STATIC UML DIAGRAMS.pptx
UNIT II STATIC UML DIAGRAMS.pptx
anguraju1
 
Software Engineering - Modelling Concepts + Class Modelling + Building the An...
Software Engineering - Modelling Concepts + Class Modelling + Building the An...Software Engineering - Modelling Concepts + Class Modelling + Building the An...
Software Engineering - Modelling Concepts + Class Modelling + Building the An...
Prakhyath Rai
 
Object oriented software engineering
Object oriented software engineeringObject oriented software engineering
Object oriented software engineering
Varsha Ajith
 
ObjectOrientedSystems.ppt
ObjectOrientedSystems.pptObjectOrientedSystems.ppt
ObjectOrientedSystems.ppt
ChishaleFriday
 
3_ObjectOrientedSystems.pptx
3_ObjectOrientedSystems.pptx3_ObjectOrientedSystems.pptx
3_ObjectOrientedSystems.pptx
RokaKaram
 
SE18_Lec 06_Object Oriented Analysis and Design
SE18_Lec 06_Object Oriented Analysis and DesignSE18_Lec 06_Object Oriented Analysis and Design
SE18_Lec 06_Object Oriented Analysis and Design
Amr E. Mohamed
 
SE_Lec 06_Object Oriented Analysis and Design
SE_Lec 06_Object Oriented Analysis and DesignSE_Lec 06_Object Oriented Analysis and Design
SE_Lec 06_Object Oriented Analysis and Design
Amr E. Mohamed
 
08 class and sequence diagrams
08   class and sequence diagrams08   class and sequence diagrams
08 class and sequence diagramskebsterz
 
Uml - An Overview
Uml - An OverviewUml - An Overview
Uml - An Overview
Raj Thilak S
 
Sda 7
Sda   7Sda   7
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
Greg Sohl
 
OOP_Module 2.pptx
OOP_Module 2.pptxOOP_Module 2.pptx
OOP_Module 2.pptx
PrasenjitKumarDas2
 
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPTCS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
leela rani
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
AnmolVerma363503
 
CHAPTER 1 - OVERVIEW OOP.ppt
CHAPTER 1 - OVERVIEW OOP.pptCHAPTER 1 - OVERVIEW OOP.ppt
CHAPTER 1 - OVERVIEW OOP.ppt
NgoHuuNhan1
 

Similar to Object Oriented Design (20)

UNIT II STATIC UML DIAGRAMS.pptx
UNIT II STATIC UML DIAGRAMS.pptxUNIT II STATIC UML DIAGRAMS.pptx
UNIT II STATIC UML DIAGRAMS.pptx
 
Software Engineering - Modelling Concepts + Class Modelling + Building the An...
Software Engineering - Modelling Concepts + Class Modelling + Building the An...Software Engineering - Modelling Concepts + Class Modelling + Building the An...
Software Engineering - Modelling Concepts + Class Modelling + Building the An...
 
Object oriented software engineering
Object oriented software engineeringObject oriented software engineering
Object oriented software engineering
 
ObjectOrientedSystems.ppt
ObjectOrientedSystems.pptObjectOrientedSystems.ppt
ObjectOrientedSystems.ppt
 
3_ObjectOrientedSystems.pptx
3_ObjectOrientedSystems.pptx3_ObjectOrientedSystems.pptx
3_ObjectOrientedSystems.pptx
 
SE18_Lec 06_Object Oriented Analysis and Design
SE18_Lec 06_Object Oriented Analysis and DesignSE18_Lec 06_Object Oriented Analysis and Design
SE18_Lec 06_Object Oriented Analysis and Design
 
SE_Lec 06_Object Oriented Analysis and Design
SE_Lec 06_Object Oriented Analysis and DesignSE_Lec 06_Object Oriented Analysis and Design
SE_Lec 06_Object Oriented Analysis and Design
 
08 class and sequence diagrams
08   class and sequence diagrams08   class and sequence diagrams
08 class and sequence diagrams
 
Uml - An Overview
Uml - An OverviewUml - An Overview
Uml - An Overview
 
Sda 7
Sda   7Sda   7
Sda 7
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
 
Ooad 2
Ooad 2Ooad 2
Ooad 2
 
OOP_Module 2.pptx
OOP_Module 2.pptxOOP_Module 2.pptx
OOP_Module 2.pptx
 
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPTCS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
CS8592-OOAD-UNIT II-STATIC UML DIAGRAMS PPT
 
Intro Uml
Intro UmlIntro Uml
Intro Uml
 
Ooad
OoadOoad
Ooad
 
Ch06
Ch06Ch06
Ch06
 
Jar chapter 2
Jar chapter 2Jar chapter 2
Jar chapter 2
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
CHAPTER 1 - OVERVIEW OOP.ppt
CHAPTER 1 - OVERVIEW OOP.pptCHAPTER 1 - OVERVIEW OOP.ppt
CHAPTER 1 - OVERVIEW OOP.ppt
 

Recently uploaded

Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 

Recently uploaded (20)

Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 

Object Oriented Design

  • 1. Object Oriented Design Sudarsun S., M.Tech Director – R & D Checktronix India Pvt Ltd Chennai 600010
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 22. Weather station - data collection sequence
  • 23.
  • 24.
  • 25.
  • 27.
  • 28.
  • 29.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37. Example class Car extends Vehicle { . . . private Tire[] tires; }
  • 38. Example UML Notation for Inheritance and Aggregation
  • 39.
  • 40. UML Relationship Symbols Open Dotted Dependency Diamond Solid Aggregation Triangle Dotted Interface Implementation Triangle Solid Inheritance Arrow Tip Line Style Symbol Relationship
  • 41.
  • 42.
  • 43. Attributes and Methods in UML Attributes and Methods in a Class Diagram
  • 44.
  • 45.
  • 46. Aggregation and Association An Association Relationship
  • 47.
  • 48.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57. Printing an Invoice – UML Diagrams The Relationships Between the Invoice Classes
  • 58.
  • 59. Method Documentation – Invoice class /** Describes an invoice for a set of purchased products. */ public class Invoice { /** Adds a charge for a product to this invoice. @param aProduct the product that the customer ordered @param quantity the quantity of the product */ public void add(Product aProduct, int quantity) { } /** Formats the invoice. @return the formatted invoice */ public String format() { } }
  • 60. Method Documentation – LineItem class /** Describes a quantity of an article to purchase and its price. */ public class LineItem { /** Computes the total cost of this line item. @return the total price */ public double getTotalPrice() { } /** Formats this item. @return a formatted string of this line item */ public String format() { } }
  • 61. Method Documentation – Product class /** Describes a product with a description and a price. */ public class Product { /** Gets the product description. @return the description */ public String getDescription() { } /** Gets the product price. @return the unit price */ public double getPrice() { } }
  • 62. Method Documentation – Address class /** Describes a mailing address. */ public class Address { /** Formats the address. @return the address as a string with three lines */ public String format() { } }
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79. Patterns by Example: Multiple displays enabled by Observer A=10% B=40% C=30% D=20% Application data A B C D A D C B Relative Percentages Y 10 40 30 20 X 15 35 35 15 Z 10 40 30 20 A B C D Change notification Requests, modifications
  • 80.
  • 81. The Observer pattern observerState= subject  getState(); Subject attach (Observer) detach (Observer) Notify () Observer Update() Concrete Observer Update() observerState Concrete Subject GetState() SetState() subjectState observers subject For all x in observers{ x  Update(); }
  • 82.
  • 84.
  • 85. Facade Pattern: Problem Subsystem classes Client Classes Need to communicate with
  • 86. Facade Pattern: Solution Subsystem classes Fac ade Client Classes
  • 88.
  • 90.
  • 92.
  • 93. The Abstract Factory Pattern AbstractFactory CreateProductA() CreateProductB() ConcreteFactory1 Client ProductA1 ProductA2 AbstractProductA ProductB2 ProductB1 AbstractProductB ConcreteFactory2 CreateProductA() CreateProductB()
  • 94. Abstract Factory Example WidgetFactory CreateScrollbar() CreateWindow() Window ScrollBar WWidgetFactory MacWidgetFactory Client WWindow MacWindow MacScrollBar WScrollBar One for each standard.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100. Changes with Rigidity The System Officially Rigid Area Where the change should be made Where the change must be made now Are we containing risk, or spreading rot?
  • 101.
  • 102. Increasing Risk Defects v. Cumulative Modifications Systems tend to become increasingly fragile over time. Intentional, planned partial rewrites may be necessary to sustain growth and maintenance. Changes Probability of introducing a bug 1.0
  • 103.
  • 104. The Trailer The Trailer
  • 105.
  • 106. What is the benefit of good DM? Interdependencies are managed, with firewalls separating aspects that need to vary independently. Fewer Trailers Slow the rot More Flexible Less fragile, the bugs are boxed in Easier to reuse Easier to make the right change
  • 107.
  • 108. First Version All designs start well The program is an overnight success! How could it be more simple, elegant, and maintainable? void copy(void) { int ch; while( (ch=ReadKeyboard()) != EOF) WritePrinter(ch); }
  • 109.
  • 110. Second Version Design bool GtapeReader = false; // remember to clear void copy(void) { int ch; while( (ch=GtapeReader ? ReadTape() : ReadKeyboard()) != EOF) WritePrinter(ch); }
  • 111. Third Version How unexpected! Requirements changed again! bool GtapeReader = false; Bool GtapePunch = false; // remember to clear void copy(void) { int ch; while( (ch=GtapeReader ? ReadTape() : ReadKeyboard()) != EOF) GtapePunch ? WritePunch(ch) : WritePrinter(ch); } It seems that sometimes we need to write to a paper tape punch. We’ve had this problem before, and just added a flag. Looks like it should work again.
  • 112. Example of a Good Design First and only version. void Copy() { int c; while( (c=getchar()) != EOF) putchar(c); } But wait! Aren’t we supposed to be learning OO design? This isn’t OO is it?
  • 113.
  • 114. Rephrased in OO interface Reader { char read(); } interface Writer { void write(char c); } public class Copy { Copy(Reader r, Writer w) { itsReader = r; itsWriter = w; } public void copy() { int c; while( (c==itsReader.read()) != EOF ) itsWriter.write(c); } private Reader itsReader; private Writer itsWriter; }
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120. Procedural (open) version enum ShapeType {circle, square}; struct Shape {enum ShapeType itsType;}; struct Circle { enum ShapeType itsType; double itsRadius; Point itsCenter; }; void DrawCircle(struct Circle*) struct Square { enum ShapeType itsType; double itsSide; Point itsTopLeft; }; void DrawSquare(struct Square*) #include <Shape.h> #include <Circle.h> #include <Square.h> typedef struct Shape* ShapePtr; void DrawAllShapes(ShapePtr list[], int n) { int i; for( i=0; i< n, i++ ) { ShapePtr s = list[i]; switch ( s->itsType ) { case square: DrawSquare((struct Square*)s); break; case circle: DrawCircle((struct Circle*)s); break; } } } Shape.h Circle.h Square.h DrawAllShapes.c
  • 121.
  • 122. A Closed Implementation Class Shape { public: virtual void Draw() const =0; }; #include <Shape.h> void DrawAllShapes(Shape* list[],int n) { for(int i=0; i< n; i++) list[i]->draw(); } Shape.h DrawAllShapes.cpp Circle.h Square.h Class Square: public Shape { public: virtual void Draw() const; }; Class Circle: public Shape { public: virtual void Draw() const; };
  • 123.
  • 124.
  • 125. Square/Rectangle A square is-a rectangle, right? So lets consider Square as a subtype of Rectangle. void Square::SetWidth(double w) { width = w; height = w; } void Square::SetHeight(double h) { width = h; height = h; } We can make it work: Uh, oh. This doesn’t quite seem to fit
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131. Dependency Inversion Principle Details should depend on abstractions. Abstractions should not depend on details. V.
  • 132.
  • 133. Procedural vs. OO Architecture Procedural Architecture Object-Oriented Architecture
  • 134. DIP Applied on Example Copy Reader Writer Keyboard Reader Printer Writer class Reader { public: virtual int read()=0; }; class Writer { public: virtual void write(int)=0; }; void Copy(Reader& r, Writer& w){ int c; while((c = r.read()) != EOF) w.write(c); } Disk Writer
  • 135.
  • 136. Interface Pollution by “collection” Distinct clients of our class have distinct interface needs.
  • 139. A Segregated ATM UI Example
  • 141.
  • 142.