eleks.comeleks.com
SOLID AND IOC PRINCIPLES
The first five principles of OOP design… And the
additional one
Mykhailo Romaniuk
Single Responsibility Principle
SRP
A class should have only one reason to change
Robert C. Martin
SRP
States that every module or class should have
responsibility over a single part of the
functionality provided by the software, and that
responsibility should be entirely encapsulated
by the class
Open/Closed Principle
OCP
Objects or entities should be open for
extension, but closed for modification
Bertrand Meyer
OCP
States that software entities (classes, modules,
functions, etc.) should be open for extension,
but closed for modification, that is, such an
entity can allow its behavior to be extended
without modifying its source code
Liskov Substitution Principle
Can a toy-dog woof without batteries?
LSP
Let f(x) be a property of objects X of type T.
Then f(y) should be true for objects Y of type S
where S is a subtype of T
Barbara Liskov
LSP
States that if S is a subtype of T, then objects of
type T may be replaced with objects of type S
without altering any of the desirable properties
of that program (correctness, task performed)
Interface Segregation Principle
ISP
Many client-specific interfaces are better than
one general-purpose interface
Robert C. Martin
ISP
States that no client should be forced to depend
on methods it does not use. Thus having
multiple grained interfaces is better that one.
Dependency Inversion Principle
DIP
One should depend upon abstractions, not on
concretions
Robert C. Martin
DIP
A. High-level modules should not depend on
low-level modules. Both should depend on
abstractions.
B. Abstractions should not depend on details.
Details should depend on abstractions.
Inversion of Control Principle
What Is IoC?
In software engineering, IoC describes a design in which
custom-written portions of a computer program receive the
flow of control from a generic, reusable library.
Wikipedia
“How To IoC”?
• Events
• Delegates
• Dependency
Injection
Dependency Injection
Dependency injection means giving an object
it’s instance variables. Really. That's it.
James Shore
What Should I Use For DI?
Windsor
Injection Types
• Constructor
Injection
• Using Property
• Thru Initialization
Method
Software Testability
If your code isn't testable, then you have a
design problem
Common Sense
What Makes Your Software Testable?
• SRP. Since type is doing only one job, you can
clearly understand what should be tested.
• LSP. Since types used can be replaced with
subtypes, mocks and stubs can be used instead
of real types.
• ISP. Since there are more granular client-specific
interfaces, you know exactly what to mock.
Let’s Review Some Concepts
• Reusable. Higher-level
components can be reused if
lower-lever components change
with time to meet the
requirements.
• Extensible. Software is easily
extended with new components
and features because design is
based on abstractions.
• Replaceable. Lower-level
components can be replaced to
meet new requirements without
modifying existing code.
• Loosely Coupled. Allows
components to perform on their
own with as little knowledge as
possible about other
components.
• Cohesive. Build you software
easily with different components
as building blocks.
• Testable. It is easy to understand
what and how to test in each
component because components
are loosely-coupled.
Thanks! Any Questions?
What can you read at home?
• Wikipedia about SOLID
https://en.wikipedia.org/wiki/SOLID_%28object-oriented_design%29
• Nice article about SOLID with examples
https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design
• Dive deeper into SOLID
http://www.butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
• SOLID explanation with examples:
http://www.codemag.com/article/1001061
• Simple explanation of DI for beginners
http://www.jamesshore.com/Blog/Dependency-Injection-Demystified.html
• IoC and DI
http://martinfowler.com/articles/injection.html
eleks.com
Inspired by Technology.
Driven by Value.

Solid and ioc principles

  • 1.
    eleks.comeleks.com SOLID AND IOCPRINCIPLES The first five principles of OOP design… And the additional one Mykhailo Romaniuk
  • 2.
  • 3.
    SRP A class shouldhave only one reason to change Robert C. Martin
  • 4.
    SRP States that everymodule or class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class
  • 5.
  • 6.
    OCP Objects or entitiesshould be open for extension, but closed for modification Bertrand Meyer
  • 7.
    OCP States that softwareentities (classes, modules, functions, etc.) should be open for extension, but closed for modification, that is, such an entity can allow its behavior to be extended without modifying its source code
  • 8.
    Liskov Substitution Principle Cana toy-dog woof without batteries?
  • 9.
    LSP Let f(x) bea property of objects X of type T. Then f(y) should be true for objects Y of type S where S is a subtype of T Barbara Liskov
  • 10.
    LSP States that ifS is a subtype of T, then objects of type T may be replaced with objects of type S without altering any of the desirable properties of that program (correctness, task performed)
  • 11.
  • 12.
    ISP Many client-specific interfacesare better than one general-purpose interface Robert C. Martin
  • 13.
    ISP States that noclient should be forced to depend on methods it does not use. Thus having multiple grained interfaces is better that one.
  • 14.
  • 15.
    DIP One should dependupon abstractions, not on concretions Robert C. Martin
  • 16.
    DIP A. High-level modulesshould not depend on low-level modules. Both should depend on abstractions. B. Abstractions should not depend on details. Details should depend on abstractions.
  • 17.
  • 18.
    What Is IoC? Insoftware engineering, IoC describes a design in which custom-written portions of a computer program receive the flow of control from a generic, reusable library. Wikipedia
  • 19.
    “How To IoC”? •Events • Delegates • Dependency Injection
  • 20.
    Dependency Injection Dependency injectionmeans giving an object it’s instance variables. Really. That's it. James Shore
  • 21.
    What Should IUse For DI? Windsor
  • 22.
    Injection Types • Constructor Injection •Using Property • Thru Initialization Method
  • 23.
    Software Testability If yourcode isn't testable, then you have a design problem Common Sense
  • 24.
    What Makes YourSoftware Testable? • SRP. Since type is doing only one job, you can clearly understand what should be tested. • LSP. Since types used can be replaced with subtypes, mocks and stubs can be used instead of real types. • ISP. Since there are more granular client-specific interfaces, you know exactly what to mock.
  • 25.
    Let’s Review SomeConcepts • Reusable. Higher-level components can be reused if lower-lever components change with time to meet the requirements. • Extensible. Software is easily extended with new components and features because design is based on abstractions. • Replaceable. Lower-level components can be replaced to meet new requirements without modifying existing code. • Loosely Coupled. Allows components to perform on their own with as little knowledge as possible about other components. • Cohesive. Build you software easily with different components as building blocks. • Testable. It is easy to understand what and how to test in each component because components are loosely-coupled.
  • 26.
  • 27.
    What can youread at home? • Wikipedia about SOLID https://en.wikipedia.org/wiki/SOLID_%28object-oriented_design%29 • Nice article about SOLID with examples https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design • Dive deeper into SOLID http://www.butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod • SOLID explanation with examples: http://www.codemag.com/article/1001061 • Simple explanation of DI for beginners http://www.jamesshore.com/Blog/Dependency-Injection-Demystified.html • IoC and DI http://martinfowler.com/articles/injection.html
  • 28.