[go: up one dir, main page]

0% found this document useful (0 votes)
16 views22 pages

Sim UDuck App

The document discusses implementing a "SimUDuck" app that simulates duck behavior. It analyzes issues developers may face, what went wrong in the initial implementation, and how to improve it based on design patterns concepts. It discusses implementing a "fly" method for ducks and whether it should go in the Duck class or a new Fly class. It reviews principles like separating what varies from what stays the same. Finally, it discusses design patterns like Strategy that are relevant and how they help satisfy SOLID principles like the Liskov substitution principle.

Uploaded by

jessieduck123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views22 pages

Sim UDuck App

The document discusses implementing a "SimUDuck" app that simulates duck behavior. It analyzes issues developers may face, what went wrong in the initial implementation, and how to improve it based on design patterns concepts. It discusses implementing a "fly" method for ducks and whether it should go in the Duck class or a new Fly class. It reviews principles like separating what varies from what stays the same. Finally, it discusses design patterns like Strategy that are relevant and how they help satisfy SOLID principles like the Liskov substitution principle.

Uploaded by

jessieduck123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

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

You might also like