Upgrade to Pro — share decks privately, control downloads, hide ads and more …

From STUPID to SOLID code!

From STUPID to SOLID code!

STUPID and SOLID are two acronyms that explain what you should and should NOT do while writing OOP code. These slides introduce a few basic principles of OOP and Design.

Online slides: http://williamdurand.fr/from-stupid-to-solid-code-slides/
Source: https://github.com/willdurand/from-stupid-to-solid-code-slides

William Durand

July 25, 2013
Tweet

More Decks by William Durand

Other Decks in Programming

Transcript

  1. FROM FROM STUPID STUPID TO TO SOLID SOLID CODE! CODE!

    A few basic principles of Object-Oriented Programming and Design.
  2. WHAT MAKES CODE WHAT MAKES CODE STUPID STUPID? ? Singleton

    Tight Coupling Untestability Premature Optimization Indescriptive Naming Duplication
  3. S SINGLETON INGLETON Programs using global state are very difficult

    to test. Programs that rely on global state hide their dependencies. Why Singletons Are Controversial Why is Singleton considered an anti pattern? So Singletons are bad, then what?
  4. T TIGHT COUPLING IGHT COUPLING Generalization of the Singleton issue.

    Also known as strong coupling. Reducing Coupling (Martin Fowler)
  5. U UNTESTABILITY NTESTABILITY Testing should not be hard! Whenever you

    don't write unit tests because you don't have time, the real issue is that your code is bad.
  6. P PREMATURE OPTIMIZATION REMATURE OPTIMIZATION Premature optimization is the root

    of all evil. — Donald Knuth There is only cost and no benefit. PrematureOptimization Anti-Pattern
  7. SOLID SOLID A term describing a collection of design principles

    for good code that was coined by Robert C. Martin also known as Uncle Bob.
  8. S SINGLE RESPONSIBILITY PRINCIPLE (SRP) INGLE RESPONSIBILITY PRINCIPLE (SRP) There

    should never be more than one reason for a class to change. The Single Responsibility Principle
  9. O OPEN/CLOSED PRINCIPLE (OCP) PEN/CLOSED PRINCIPLE (OCP) Software entities should

    be open for extension, but closed for modification. The Open-Closed Principle
  10. L LISKOV SUBSTITUTION PRINCIPLE (LSP) ISKOV SUBSTITUTION PRINCIPLE (LSP) Objects

    in a program should be replaceable with instances of their subtypes without altering the correctness of the program. Liskov Substitution Principle The Liskov Substitution Principle
  11. IINTERFACE SEGREGATION PRINCIPLE (ISP) NTERFACE SEGREGATION PRINCIPLE (ISP) Many client-specific

    interfaces are better than one general-purpose interface. The Interface Segregation Principle
  12. D DEPENDENCY INVERSION PRINCIPLE (DIP) EPENDENCY INVERSION PRINCIPLE (DIP) High

    level modules should not depend upon low level modules. Both should depend upon abstractions. Abstractions should not depend upon details. Details should depend upon abstractions. DIP in the Wild Dependency Inversion Principle The Dependency Inversion Principle Dependency Injection Is NOT The Same As The Dependency Inversion Principle
  13. CONCLUSION CONCLUSION Avoiding tight coupling is the key! Use your

    brain. Writing SOLID code is not that hard.