SlideShare una empresa de Scribd logo
1 de 19
Object Oriented Design


    Serhiy Oplakanets @ Lohika, 2010
Agenda


• Symptoms of Bad Design
• Basic Principles of Object Oriented Design
Symptoms of Bad
         Design

• Rigidity
• Fragility
• Immobility
• Viscosity
Rigidity

• Changes are difficult and painful.
• Every change requires cascade of changes in
  dependent modules.
• Scope of change is unpredictable.
• Your manager has a favorite scope
  multiplier, usually more than 2.
Fragility

• Closely related to Rigidity.
• You can never predict the impact of change.
• You never know what will break.
• The “christmas tree” (Hi, Jilles!)
Basic Principles of OOD

• Single Responsibility Principles
• Open-Closed Principle
• Liskov Substitution Principle
• Interface Segregation Principle
• Dependency Inversion Principle
Single Responsibility
        Principle


• A class should have one and only one reason
  to change.
How to Spot SRP
       Violation?
• Member groups or even coalitions :)
• Boolean flags
• Hard to name classes
• Monster classes: *Manager, *Controller,
  *Util, Context, ...
• Long unit tests
• Hard to test-double units
Open-Closed Principle


• Modules should be open for extension but
  closed for modification.
Friends of OCP


• Design Patterns:
 • Visitor
 • Decorator
Liskov Substitution
         Principle

• Let q(x) be a property provable about objects x
  of type T.Then q(y) should be provable for
  objects y of type S where S is a subtype of T.
• Basically means that children classes should
  not break parent’s interface
How to Spot LSP
          Violation?
•   Derivative that tries to do less than base class

•   instanceof checks

•   Hiding or stubbing parent methods
    • void    someMethod() {}

    • void someMethod(){throw new
      ShouldNotBeCalledException(“...”);}

•   Polymorphic if statements :)
Dependency Inversion
     Principle
• High-level modules should not depend on
  low-level modules. Both should depend on
  abstractions.
• Abstractions should not depend upon
  details. Details should depend upon
  abstractions.
DIP Violation Example

class UserDao {
  User find(String login, String password) {
    Database database = new MySQLDatabase();
    // run queries and so on to create user ...
    return user;
  }
}
DIP Example.
                      Refactored
class UserDao {
 DataSource dataSource;

    UserDao(DataSource dataSource) {
      this.dataSource = dataSource;
    }

    User find(String login, String password) {
      // use dataSource to create user object ...
      return user;
    }
}
DIP Example.Continued

interface DataSource {
  Map<Key, Value> read(String container);
  void update(String container, Map<Key, Value> fields);
  void create(String container, Map<Key, Value> fields);
}
Why adhere to DIP?
Friends of DIP
•   Abstractions(Interfaces/Abstract Classes/...)
•   Patterns
    •   Factory, Abstract Factory
    •   Adapter
    •   Service Locator
    •   Dependency Injection
•   Inversion of Control Principle
Questions?


• Have I mentioned good OO Design is hard
  to implement, btw?

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Do we need SOLID principles during software development?
Do we need SOLID principles during software development?Do we need SOLID principles during software development?
Do we need SOLID principles during software development?
 
Single Responsibility Principle
Single Responsibility PrincipleSingle Responsibility Principle
Single Responsibility Principle
 
Clean code & design patterns
Clean code & design patternsClean code & design patterns
Clean code & design patterns
 
Clean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
Clean Code - Design Patterns and Best Practices at Silicon Valley Code CampClean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
Clean Code - Design Patterns and Best Practices at Silicon Valley Code Camp
 
What does OOP stand for?
What does OOP stand for?What does OOP stand for?
What does OOP stand for?
 
Simply - OOP - Simply
Simply - OOP - SimplySimply - OOP - Simply
Simply - OOP - Simply
 
CLEAN CODE
CLEAN CODECLEAN CODE
CLEAN CODE
 
Clean code quotes - Citações e provocações
Clean code quotes - Citações e provocaçõesClean code quotes - Citações e provocações
Clean code quotes - Citações e provocações
 
Java day2016 "Reinventing design patterns with java 8"
Java day2016 "Reinventing design patterns with java 8"Java day2016 "Reinventing design patterns with java 8"
Java day2016 "Reinventing design patterns with java 8"
 
Beginning OOP in PHP
Beginning OOP in PHPBeginning OOP in PHP
Beginning OOP in PHP
 
Paris Web - Javascript as a programming language
Paris Web - Javascript as a programming languageParis Web - Javascript as a programming language
Paris Web - Javascript as a programming language
 
Oop java Concept
Oop java ConceptOop java Concept
Oop java Concept
 
Clean code
Clean codeClean code
Clean code
 
Design patterns illustrated-2015-03
Design patterns illustrated-2015-03Design patterns illustrated-2015-03
Design patterns illustrated-2015-03
 
Value Objects
Value ObjectsValue Objects
Value Objects
 
Styled Components & React.js
Styled Components & React.jsStyled Components & React.js
Styled Components & React.js
 
Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)Design pattern (Abstract Factory & Singleton)
Design pattern (Abstract Factory & Singleton)
 
Advanced Object Oriented JavaScript (prototype, closure, scope, design patterns)
Advanced Object Oriented JavaScript (prototype, closure, scope, design patterns)Advanced Object Oriented JavaScript (prototype, closure, scope, design patterns)
Advanced Object Oriented JavaScript (prototype, closure, scope, design patterns)
 
Design Patterns & JDK Examples
Design Patterns & JDK ExamplesDesign Patterns & JDK Examples
Design Patterns & JDK Examples
 
Mental models, complexity and software
Mental models, complexity and softwareMental models, complexity and software
Mental models, complexity and software
 

Destacado

Software design principles
Software design principlesSoftware design principles
Software design principles
Ritesh Singh
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design Principles
Samuel Breed
 

Destacado (20)

SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design Principles
 
SOLID - Principles of Object Oriented Design
SOLID - Principles of Object Oriented DesignSOLID - Principles of Object Oriented Design
SOLID - Principles of Object Oriented Design
 
Solid principles of oo design
Solid principles of oo designSolid principles of oo design
Solid principles of oo design
 
Advanced Object-Oriented/SOLID Principles
Advanced Object-Oriented/SOLID PrinciplesAdvanced Object-Oriented/SOLID Principles
Advanced Object-Oriented/SOLID Principles
 
Object Oriented Design SOLID Principles
Object Oriented Design SOLID PrinciplesObject Oriented Design SOLID Principles
Object Oriented Design SOLID Principles
 
SOLID Principles and Design Patterns
SOLID Principles and Design PatternsSOLID Principles and Design Patterns
SOLID Principles and Design Patterns
 
Clean code
Clean codeClean code
Clean code
 
Design Smells
Design SmellsDesign Smells
Design Smells
 
Open Closed Principle kata
Open Closed Principle kataOpen Closed Principle kata
Open Closed Principle kata
 
The Professional Software Engineer
The Professional Software EngineerThe Professional Software Engineer
The Professional Software Engineer
 
Software design principles
Software design principlesSoftware design principles
Software design principles
 
Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...
Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...
Clean Code I - Design Patterns and Best Practices at SoCal Code Camp San Dieg...
 
The Solid Principles
The Solid PrinciplesThe Solid Principles
The Solid Principles
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design Principles
 
Refactoring for Software Design Smells - 1 day Workshop
Refactoring for Software Design Smells - 1 day Workshop Refactoring for Software Design Smells - 1 day Workshop
Refactoring for Software Design Smells - 1 day Workshop
 
Introduction to SOLID Principles
Introduction to SOLID PrinciplesIntroduction to SOLID Principles
Introduction to SOLID Principles
 
Clean code
Clean codeClean code
Clean code
 
Towards a Principle-based Classification of Structural Design Smells
Towards a Principle-based Classification of Structural Design SmellsTowards a Principle-based Classification of Structural Design Smells
Towards a Principle-based Classification of Structural Design Smells
 
PHAME: Principles of Hierarchy Abstraction Modularization and Encapsulation
PHAME: Principles of Hierarchy Abstraction Modularization and EncapsulationPHAME: Principles of Hierarchy Abstraction Modularization and Encapsulation
PHAME: Principles of Hierarchy Abstraction Modularization and Encapsulation
 

Similar a "SOLID" Object Oriented Design Principles

The View object orientated programming in Lotuscript
The View object orientated programming in LotuscriptThe View object orientated programming in Lotuscript
The View object orientated programming in Lotuscript
Bill Buchan
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
rsebbe
 
Design Pattern Zoology
Design Pattern ZoologyDesign Pattern Zoology
Design Pattern Zoology
Josh Adell
 

Similar a "SOLID" Object Oriented Design Principles (20)

2009 training - tim m - object oriented programming
2009   training - tim m - object oriented programming2009   training - tim m - object oriented programming
2009 training - tim m - object oriented programming
 
Improving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design PrinciplesImproving Software Quality Using Object Oriented Design Principles
Improving Software Quality Using Object Oriented Design Principles
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
 
The View object orientated programming in Lotuscript
The View object orientated programming in LotuscriptThe View object orientated programming in Lotuscript
The View object orientated programming in Lotuscript
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
 
DSL's with Groovy
DSL's with GroovyDSL's with Groovy
DSL's with Groovy
 
Things Every Professional Programmer Should Know
Things Every Professional Programmer Should KnowThings Every Professional Programmer Should Know
Things Every Professional Programmer Should Know
 
Design for Testability
Design for TestabilityDesign for Testability
Design for Testability
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 
Improving the Design of Existing Software
Improving the Design of Existing SoftwareImproving the Design of Existing Software
Improving the Design of Existing Software
 
Object-oriented design principles
Object-oriented design principlesObject-oriented design principles
Object-oriented design principles
 
Design Pattern Zoology
Design Pattern ZoologyDesign Pattern Zoology
Design Pattern Zoology
 
The maze of Design Patterns & SOLID Principles
The maze of Design Patterns & SOLID PrinciplesThe maze of Design Patterns & SOLID Principles
The maze of Design Patterns & SOLID Principles
 
Improving the Quality of Existing Software - DevIntersection April 2016
Improving the Quality of Existing Software - DevIntersection April 2016Improving the Quality of Existing Software - DevIntersection April 2016
Improving the Quality of Existing Software - DevIntersection April 2016
 
Improving The Quality of Existing Software
Improving The Quality of Existing SoftwareImproving The Quality of Existing Software
Improving The Quality of Existing Software
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 
Decorator Pattern
Decorator PatternDecorator Pattern
Decorator Pattern
 
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
 
Single Responsibility Principle @ Clean Code Alliance Meetup
Single Responsibility Principle @ Clean Code Alliance MeetupSingle Responsibility Principle @ Clean Code Alliance Meetup
Single Responsibility Principle @ Clean Code Alliance Meetup
 
L22 Design Principles
L22 Design PrinciplesL22 Design Principles
L22 Design Principles
 

Último

Último (20)

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

"SOLID" Object Oriented Design Principles

  • 1. Object Oriented Design Serhiy Oplakanets @ Lohika, 2010
  • 2. Agenda • Symptoms of Bad Design • Basic Principles of Object Oriented Design
  • 3. Symptoms of Bad Design • Rigidity • Fragility • Immobility • Viscosity
  • 4. Rigidity • Changes are difficult and painful. • Every change requires cascade of changes in dependent modules. • Scope of change is unpredictable. • Your manager has a favorite scope multiplier, usually more than 2.
  • 5. Fragility • Closely related to Rigidity. • You can never predict the impact of change. • You never know what will break. • The “christmas tree” (Hi, Jilles!)
  • 6. Basic Principles of OOD • Single Responsibility Principles • Open-Closed Principle • Liskov Substitution Principle • Interface Segregation Principle • Dependency Inversion Principle
  • 7. Single Responsibility Principle • A class should have one and only one reason to change.
  • 8. How to Spot SRP Violation? • Member groups or even coalitions :) • Boolean flags • Hard to name classes • Monster classes: *Manager, *Controller, *Util, Context, ... • Long unit tests • Hard to test-double units
  • 9. Open-Closed Principle • Modules should be open for extension but closed for modification.
  • 10. Friends of OCP • Design Patterns: • Visitor • Decorator
  • 11. Liskov Substitution Principle • Let q(x) be a property provable about objects x of type T.Then q(y) should be provable for objects y of type S where S is a subtype of T. • Basically means that children classes should not break parent’s interface
  • 12. How to Spot LSP Violation? • Derivative that tries to do less than base class • instanceof checks • Hiding or stubbing parent methods • void someMethod() {} • void someMethod(){throw new ShouldNotBeCalledException(“...”);} • Polymorphic if statements :)
  • 13. Dependency Inversion Principle • High-level modules should not depend on low-level modules. Both should depend on abstractions. • Abstractions should not depend upon details. Details should depend upon abstractions.
  • 14. DIP Violation Example class UserDao { User find(String login, String password) { Database database = new MySQLDatabase(); // run queries and so on to create user ... return user; } }
  • 15. DIP Example. Refactored class UserDao { DataSource dataSource; UserDao(DataSource dataSource) { this.dataSource = dataSource; } User find(String login, String password) { // use dataSource to create user object ... return user; } }
  • 16. DIP Example.Continued interface DataSource { Map<Key, Value> read(String container); void update(String container, Map<Key, Value> fields); void create(String container, Map<Key, Value> fields); }
  • 18. Friends of DIP • Abstractions(Interfaces/Abstract Classes/...) • Patterns • Factory, Abstract Factory • Adapter • Service Locator • Dependency Injection • Inversion of Control Principle
  • 19. Questions? • Have I mentioned good OO Design is hard to implement, btw?

Notas del editor

  1. \n
  2. \n
  3. \n
  4. rigid is antonym to agile.\n
  5. \n
  6. \n
  7. \n
  8. \n
  9. - Invented by Bertrand Meyer\n- Adding new functionality by adding new code, not editing old one.\n- Abstractions\n
  10. \n
  11. Design by Contract\n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n