KeyShowR
Explore Experience Empower
food on a child who's not hungry
Don't push
It is hard to change because every change affects too many other parts of the system.
When you make a change, unexpected parts of the system break
It is hard to reuse in another application because it cannot be disentangled from the
current application
costtotal = costdevelop + costmaintain
costmaintain = costunderstand + costchange + costtest + costdeploy
Implementation Patterns - Kent
THE R P
“ THERE SHOULD NEVER BE MORE THAN ONE
REASON
FOR A CLASS TO CHANGE “
”States that every class should have a single responsibility,
and that responsibility should be entirely encapsulated by the class
All its services should be narrowly aligned with that responsibility.”
If a class assumes more than one responsibility,
then there will be more than one reason for it to change
family of functions that serve one particular
SRP PROBLEM
STATEMENT
SRP VIOLATION: SYMPTOMS
 Unrelated functions in the same class
 SQL and HTML in the same module
 Business rules in JSPs
 Business logic is Framework aware
 UI code knows about DB/Business logic
 FAT classes
 Class name having phrase like “Manager/Utils”
SRP
FIX SRP VIOLATION
 Separate functions that change for different
reason to a different module/class
 Create boundaries between DB/UI/Business rules
 Identify families of functions and move them to
new classes
 Move business logic from framework classes to
new modules , use delegate pattern
 ??
THE CP
‘SOFTWARE ENTITIES (CLASSES, MODULES, FUNCTIONS, ETC.)
SHOULD BE OPEN FOR EXTENSION, BUT CLOSED FOR
MODIFICATION.’
“ says that you should design modules that never change.
when requirements change, you extend the behavior of such modules
by adding new code, not by changing old code that already works”
The primary mechanisms behind the OCP
are abstraction and polymorphism
OCP PROBLEM
STATEMENT
OVER ENGINEERED OCP
THE SP
“ FUNCTIONS THAT USE POINTERS OR
REFERENCES
TO BASE CLASSES MUST BE ABLE TO USE
OBJECTS
OF DERIVED CLASSES WITHOUT KNOWING IT “
If there is a function which does not conform to the LSP, then that function uses a
pointer
or reference to a base class, but must Know about all the derivatives of that base class
Lsp example:
void DrawShape(Shape s)
{
if (s instanceof Square)
s.DrawSquare( );
else if (s instanceof Circle)
s.DrawCircle();
}
refused-bequest
LSP VIOLATION: SYMPTOMS
 Derived class throws some exception that the
base class users don’t expect.
 Derived class having do-nothing(){} functions.
 Methods throwing exceptions unconditionally.
 Classes having TYPE checking code.
 Base class having dependency to derived classes.
 ??
FIX LSP VIOLATION
 Apply ISP
 Break the IS A relation (representatives don’t
share the relations ships of the things they
represent )
 ??
LSP PROBLEM STATEMENT
THE SP
States CLIENTS SHOULD NOT BE FORCED
TO DEPEND UPON INTERFACES
THAT THEY DO NOT USE
Make fine grained interfaces that are client specific.
THE IP
It is hard to change because every change affects too many other parts of the system.
When you make a change, unexpected parts of the system break
It is hard to reuse in another application because it cannot be disentangled from the current application
“ States that modules that encapsulate high
level policy should not depend upon
modules that implement details.”
CAN YOU PLAY MY GAME ?
Duncan Fletcher

SOLID Principles : set of five design principles in object-oriented programming

  • 1.
    KeyShowR Explore Experience Empower foodon a child who's not hungry Don't push
  • 2.
    It is hardto change because every change affects too many other parts of the system. When you make a change, unexpected parts of the system break It is hard to reuse in another application because it cannot be disentangled from the current application costtotal = costdevelop + costmaintain costmaintain = costunderstand + costchange + costtest + costdeploy Implementation Patterns - Kent
  • 3.
    THE R P “THERE SHOULD NEVER BE MORE THAN ONE REASON FOR A CLASS TO CHANGE “ ”States that every class should have a single responsibility, and that responsibility should be entirely encapsulated by the class All its services should be narrowly aligned with that responsibility.” If a class assumes more than one responsibility, then there will be more than one reason for it to change family of functions that serve one particular
  • 4.
  • 5.
    SRP VIOLATION: SYMPTOMS Unrelated functions in the same class  SQL and HTML in the same module  Business rules in JSPs  Business logic is Framework aware  UI code knows about DB/Business logic  FAT classes  Class name having phrase like “Manager/Utils”
  • 6.
  • 7.
    FIX SRP VIOLATION Separate functions that change for different reason to a different module/class  Create boundaries between DB/UI/Business rules  Identify families of functions and move them to new classes  Move business logic from framework classes to new modules , use delegate pattern  ??
  • 8.
    THE CP ‘SOFTWARE ENTITIES(CLASSES, MODULES, FUNCTIONS, ETC.) SHOULD BE OPEN FOR EXTENSION, BUT CLOSED FOR MODIFICATION.’ “ says that you should design modules that never change. when requirements change, you extend the behavior of such modules by adding new code, not by changing old code that already works” The primary mechanisms behind the OCP are abstraction and polymorphism
  • 9.
  • 10.
  • 11.
    THE SP “ FUNCTIONSTHAT USE POINTERS OR REFERENCES TO BASE CLASSES MUST BE ABLE TO USE OBJECTS OF DERIVED CLASSES WITHOUT KNOWING IT “ If there is a function which does not conform to the LSP, then that function uses a pointer or reference to a base class, but must Know about all the derivatives of that base class Lsp example: void DrawShape(Shape s) { if (s instanceof Square) s.DrawSquare( ); else if (s instanceof Circle) s.DrawCircle(); } refused-bequest
  • 12.
    LSP VIOLATION: SYMPTOMS Derived class throws some exception that the base class users don’t expect.  Derived class having do-nothing(){} functions.  Methods throwing exceptions unconditionally.  Classes having TYPE checking code.  Base class having dependency to derived classes.  ??
  • 13.
    FIX LSP VIOLATION Apply ISP  Break the IS A relation (representatives don’t share the relations ships of the things they represent )  ??
  • 14.
  • 15.
    THE SP States CLIENTSSHOULD NOT BE FORCED TO DEPEND UPON INTERFACES THAT THEY DO NOT USE Make fine grained interfaces that are client specific.
  • 16.
    THE IP It ishard to change because every change affects too many other parts of the system. When you make a change, unexpected parts of the system break It is hard to reuse in another application because it cannot be disentangled from the current application “ States that modules that encapsulate high level policy should not depend upon modules that implement details.”
  • 17.
    CAN YOU PLAYMY GAME ? Duncan Fletcher

Editor's Notes

  • #2  1.Discussion about primary value and secondary value. Get the software to work is --secondary value Shape and structure the software that is easy to change is --primary value A system that meets the current requirements of the current User but harder to change has High secondary value but Low primary value --Discuss the drawbacks sustainable profitability of a system is depends on ---the primary value 2 .Challenges in creating primary value ---Discuss---- Rigidity Fragility Immobility costtotal = costdevelop + costmaintain
  • #3 class knowing lot will have high fan-out Ex- DB api Business logic Reporting/formating --colocation of responsibilities couples actors --- report change causes recompilation in the classes though they don't use any report related functions.
  • #8 change the behavior of a module with out changing the source code of the module. every time we add a new feature we do so by adding new code not by changing old code. write once and never worry about it. ( main violates this ,it is responsible for loading the dependencies). separate the extensible behavior to abstraction.
  • #11 Derived class throw some exception that the base class users don’t expect. Latent violation of OCP It causes from undefined behavior (unpredictable) The representatives don’t share the relations ships of the things they represent. ( square, Rectangle )
  • #15 Don’t depend on things that you don’t need.