Design Patterns
Preparer: Chip Salim
Thursday, April 7 2017
Preface
- Re-fresher & Discovery
- Change always happens
- Increase communication
- Thinking in patterns
Driving Factors:
Foundation
A Pie
- Abstraction
- Polymorphism
- Inheritance
- Encapsulation
OO Basics
Foundation
OO Principles
-
A class should only have 1 reason to change (Single Responsibility Principle)
-
Don't repeat the same code (DRY Principle)
-
Depend on abstraction not on concrete classes (Dependency Injection Principle)
-
Favor composition over inheritance
-
Encapsulate what varies (Interface Segregation Principle)
-
Don't call us, we'll call you (Hollywood Principle)
-
Classes should be open for extension but closed for modification (Open Closed Principle)
-
Only talk to your friends
-
Program to interfaces, not implementation (Liskov Substitution Principle)
-
Strive for loosely coupled designs between objects that interact
Design Patterns are and are not
- DP are created from discoveries of recurring problems
- DP are best practices formulated to overcome such problems
- DP are general design solutions to resolve any constraints when achieving your coding goals
- DP is art
- DP is tools
- DP adds efficiency
- DP are not coding solutions but guidelines
- DP are not meant to add complexity
- DP are not always immediately obvious
When to use and when not to use DP
- KISS first
- Think over and decide the trade-off
- Address issues of change in software
- Size doesn't matter.
- Based on experience and knowledge
- A hunch
- Refactor
Let a DP emerge from your designs
Make DP one of the options in the design
When to use DP
- Refactoring time
- Based on experience and knowledge
- DP are not coding solutions but guidelines
- DP are not meant to add complexity
- DP are not always obvious
How to use DP
- Use Class Diagram
- Use DP Catalog
- Must posses strong OOB
- Must understand the underlying OOP
- Talk to your peers
- OK to alter
Benefit
- Increase Communication
- Building flexible, reusable, maintanable apps
- Reduce or even eliminate complexity from existing codes
- Refactor - Often introduce more layers.
Trade Off
DP Types
Behavioral
Creational
Structural
Conccurency
Design Patterns Catalog
dofactory.com
sourcemaking.com
Strategy Pattern
Thank You Por Favor
Feedback
Contribute by learning
Contact me!
Design Patterns feat. Strategy Pattern
By ilusi
Design Patterns feat. Strategy Pattern
- 96