KEMBAR78
Design Principles to design Patterns | PPTX
P R E S E N T E D B Y F A I Z A N H A I D E R
Design Principles to Design
Patterns
What are Design Principles
 Design principles are the desirable goals that one aims to
achieve. Design patterns are tools one can use to realize
those goals.
 It's therefore better to learn design principles first
because then you can easily understand what (and why)
a pattern is trying to achieve.
 Design principles are guidelines to be followed
throughout the software development process. Design
patterns are well accepted solutions to recurring design
problems.
 In other words: design patterns employ design
principles.
Why Use Design Principles?
 Avoid Bad Code like
 Rigidity - It is hard to change because every change
affects too many other parts of the system.
 Fragility - When you make a change, unexpected
parts of the system break.
 Immobility - It is hard to reuse in another
application because it cannot be disentangled from
the current application.
Some Desing Principles
 Open close Principle
 Dependency Inversion Principle
 Interface Segregation Principle
 Single Responsibility Principle
 Liskov's Substitution Principle
1. Open close Principle
 Software entities like classes, modules and functions
should be open for extension but closed for
modifications.
2. Dependency Inversion Principle
 High-level modules should not depend on low-level
modules. Both should depend on abstractions.
 Abstractions should not depend on details. Details
should depend on abstractions.
3. Interface Segregation Principle
 Clients should not be forced to depend upon
interfaces that they don't use.
 Avoid fat interfaces like if we code interface worker
then should keep in mind that all the workers like
worker, manager, director and robots would
implement that interface.
 Fat interfaces can be segregated using the Adapter
pattern.
 Instead of one fat interface use small ones with sub
tasks
4. Single Responsibility Principle
 A class should have only one reason to change.
5. Liskov's Substitution Principle
 Derived types must be completely substitutable for
their base types.
 Extension of the Open Close Principle in terms of
behavior meaning that we must make sure that new
derived classes are extending the base classes
without changing their behavior.
What are Design Patterns?
 Patterns focus on different types of
problems. Related patterns are grouped
together and assigned a type
 1. Creational Patterns
2. Structural Patterns
3. Behavioral Patterns
1. Creational Patterns
 All about the class instantiation
 Uses class-creation patterns and object-creational
patterns.
 Class-creation pattern uses inheritance effectively in the
instantiation process while object-creation pattern uses
delegation to get the job done
 1. Factory Pattern
 2. Abstract Factory Pattern
 3. Builder Pattern
 4. Prototype Pattern
 5. Singleton Pattern
2. Structural Patterns
 How objects and classes can be combined to form larger structures
 Class patterns describe abstraction using inheritance and
describe how it can be used to provide more useful program
interface.
 Object patterns describe how objects can be associated and
composed to form larger, more complex structures.
 1. Adapter Pattern
 2. Bridge Pattern
 3. Composite Pattern
 4. Decorator Pattern
 5. Facade Pattern
 6. Flyweight Pattern
 7. Proxy Pattern
3. Behavioral Patterns
 specifically concerned with communication (interaction) between the objects.
 Object communicating with each other and loosely coupled. The loose coupling is
the key to n-tier architectures
 The implementations and the client should be loosely coupled in order to avoid
hard-coding and dependencies.
 1. Chain of Resposibility Pattern
 2. Command Pattern
 3. Interpreter Pattern
 4. Iterator Pattern
 5. Mediator Pattern
 6. Momento Pattern
 7. Observer Pattern
 8. State Pattern
 9. Strategy Pattern
 10. Template Pattern
 11. Visitor Pattern
Conclusion
 Design principles represent a set of guidelines that
helps us to avoid having a bad design.
 While Design patterns are solution to specific
problems.
 We use Design patterns to implement a design
principle.
 If Design principles are End Game then Design
Patterns are the way to get There.

Design Principles to design Patterns

  • 1.
    P R ES E N T E D B Y F A I Z A N H A I D E R Design Principles to Design Patterns
  • 2.
    What are DesignPrinciples  Design principles are the desirable goals that one aims to achieve. Design patterns are tools one can use to realize those goals.  It's therefore better to learn design principles first because then you can easily understand what (and why) a pattern is trying to achieve.  Design principles are guidelines to be followed throughout the software development process. Design patterns are well accepted solutions to recurring design problems.  In other words: design patterns employ design principles.
  • 3.
    Why Use DesignPrinciples?  Avoid Bad Code like  Rigidity - It is hard to change because every change affects too many other parts of the system.  Fragility - When you make a change, unexpected parts of the system break.  Immobility - It is hard to reuse in another application because it cannot be disentangled from the current application.
  • 4.
    Some Desing Principles Open close Principle  Dependency Inversion Principle  Interface Segregation Principle  Single Responsibility Principle  Liskov's Substitution Principle
  • 5.
    1. Open closePrinciple  Software entities like classes, modules and functions should be open for extension but closed for modifications.
  • 6.
    2. Dependency InversionPrinciple  High-level modules should not depend on low-level modules. Both should depend on abstractions.  Abstractions should not depend on details. Details should depend on abstractions.
  • 7.
    3. Interface SegregationPrinciple  Clients should not be forced to depend upon interfaces that they don't use.  Avoid fat interfaces like if we code interface worker then should keep in mind that all the workers like worker, manager, director and robots would implement that interface.  Fat interfaces can be segregated using the Adapter pattern.  Instead of one fat interface use small ones with sub tasks
  • 8.
    4. Single ResponsibilityPrinciple  A class should have only one reason to change.
  • 9.
    5. Liskov's SubstitutionPrinciple  Derived types must be completely substitutable for their base types.  Extension of the Open Close Principle in terms of behavior meaning that we must make sure that new derived classes are extending the base classes without changing their behavior.
  • 10.
    What are DesignPatterns?  Patterns focus on different types of problems. Related patterns are grouped together and assigned a type  1. Creational Patterns 2. Structural Patterns 3. Behavioral Patterns
  • 11.
    1. Creational Patterns All about the class instantiation  Uses class-creation patterns and object-creational patterns.  Class-creation pattern uses inheritance effectively in the instantiation process while object-creation pattern uses delegation to get the job done  1. Factory Pattern  2. Abstract Factory Pattern  3. Builder Pattern  4. Prototype Pattern  5. Singleton Pattern
  • 12.
    2. Structural Patterns How objects and classes can be combined to form larger structures  Class patterns describe abstraction using inheritance and describe how it can be used to provide more useful program interface.  Object patterns describe how objects can be associated and composed to form larger, more complex structures.  1. Adapter Pattern  2. Bridge Pattern  3. Composite Pattern  4. Decorator Pattern  5. Facade Pattern  6. Flyweight Pattern  7. Proxy Pattern
  • 13.
    3. Behavioral Patterns specifically concerned with communication (interaction) between the objects.  Object communicating with each other and loosely coupled. The loose coupling is the key to n-tier architectures  The implementations and the client should be loosely coupled in order to avoid hard-coding and dependencies.  1. Chain of Resposibility Pattern  2. Command Pattern  3. Interpreter Pattern  4. Iterator Pattern  5. Mediator Pattern  6. Momento Pattern  7. Observer Pattern  8. State Pattern  9. Strategy Pattern  10. Template Pattern  11. Visitor Pattern
  • 14.
    Conclusion  Design principlesrepresent a set of guidelines that helps us to avoid having a bad design.  While Design patterns are solution to specific problems.  We use Design patterns to implement a design principle.  If Design principles are End Game then Design Patterns are the way to get There.