Skip to content

Commit

Permalink
Improving Readme and adding Strategy pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
itsgk92 committed Nov 21, 2019
1 parent 049cb2c commit a7cf174
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions README.md
@@ -1,5 +1,5 @@
# Design and DesignPatterns
####About
#### About

This is a repository which I use for learning design patterns.
This is formed as a notes with the book **Head First Design Patterns**
Expand All @@ -21,7 +21,24 @@ separate (*encpsulate*) them from what stays the same.

# Design Patterns

####Strategy Pattern
Defines a family of algorithms, encapsulates each one and makes them interchangeable.
#### Strategy Pattern
>Defines a family of algorithms, encapsulates each one and makes them interchangeable.
Strategy lets algorithm vary independently from clients that use it.

Problem in hand?

So *Duck* base class has implementations of a duck. Now the new requirement
is to make ducks fly.

![Make ducks to fly](/assets/Strategy-problem.jpg "Make ducks fly")

We can simply add fly method to base class - problem solved.
But some rubber ducks can also fly now. so simply override to null?

What if we have some other behaviour next? So **encapsulate** the changing behaviour,
create a **composition** so that duck **Has-a** behaviour that can be changed during runtime.
So behaviours are a *family of encapsulated algorithm that vary independently for each duck client.*

So the implementation looks like this.
![Encapsulate Fly as algorithm so duck clients can use it independently](/assets/Strategy-solution.jpg
"Encapsulate Fly as algorithm so duck clients can use it independently")
Binary file added assets/Strategy-problem.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Strategy-solution.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a7cf174

Please sign in to comment.