SimUDuck app
copyright @2020, E. Freeman, Kathy Sierra, Head First
Design Patterns
Also we'll analyze
• what kind of issues developers will face,
• what went wrong in the implementation
• what things we would do differently
• what we can learn about it reviewing some well know
concepts.
• Of course what will be the best way to do it.
Duck pond
Mallard Read head
Brainstorming sesión over goft
Duck fly
How would you implement it?
• A – Create a new method in Mallard / Read Head duck class/es
• B – Create fly method in Duck class
• C - Create a fly class
• D - other
Rubber duckies flying
What would you do to fix the issue?
• A – Override fly method in a duck subclass if is needed.
• B – Override fly method in Duck class
• C - Isolate fly method by adding a new class.
• D - other
Wooden duck
Review
• Override super class behavior breaking Liskov substitution principle.
• We can’t make ducks dance.
• Changes can unintentionally affect other ducks behavior.
How about an
interface?
Review
• Duplicated code
Design Principle
• “Identify the aspects of your
application that vary and separate
them from what stays the same”.
Design Principle
• As simple as this concept is, it forms the
basis for almost every design pattern.
All patterns provide a way to let some
part of a system vary independently of
all other parts.
Separating what changes from what stays the
same
Strategy pattern
• Wikipedia
• is a behavioral software design pattern that enables selecting an algorithm
at runtime.
• Refactoring guru.
• Strategy is a behavioral design pattern that lets you define a family of
algorithms, put each of them into a separate class, and make their
objects interchangeable.
• Gang of Four Design patterns
• Define a family of algorithms, encapsulate each one, and make . Strategy
lets the algorithm vary independently from clients that use it.
Solid
Que principios solid cumple.
S
O
L
I
D
Links
• http://www.uml.org.cn/c++/pdf/DesignPatterns.pdf
• http://ce.sharif.edu/courses/98-99/2/ce484-1/resources/root/Design
%20Patterns/Eric%20Freeman,%20Elisabeth%20Freeman,%20Kathy
%20Sierra,%20Bert%20Bates-Head%20First%20Design%20Patterns
%20-OReilly%20(2008).pdf
Broke types
• Class bigger than 100 lines – Single principle
• Add/ Change behavior in a method – Open and closed
• If you override a super class – Liskov substitution
• If you are force to implement methods you don’t need – Interface
segregation.
• If your methods param are Concrete objects – Inversion of Control
• new key word - Anti pattern