# Better Understand the 'Strategy' Design Pattern

Filed under:
|
|
|
|
##### strategy

Greetings

Hope you all are doing great. I have been interested in design patterns for a while and started reading 'Head First Design Patterns'. I started with the first pattern called the 'Strategy' pattern. I went through the problem outlined in the images below and first tried to propose a solution myself so I could really grasp the importance of the pattern. So my question is that why is my solution ( below ) to the problem outlined in the images below not good enough. What are the good / bad points of my solution vs the pattern? What makes the pattern clearly the only viable solution ? Thanks for you input, hope it will help me better understand the pattern.

MY SOLUTION

Parent Class: DUCK

``````<?php
class Duck
{
public  \$swimmable;
public  \$quackable;
public  \$flyable;

function display()
{
echo "A Duck Looks Like This<BR/>";
}

function  quack()
{
if(\$this->quackable==1)
{
echo("Quack<BR/>");
}
}

function swim()
{
if(\$this->swimmable==1)
{
echo("Swim<BR/>");
}
}

function  fly()
{
if(\$this->flyable==1)
{
echo("Fly<BR/>");
}
}

}
?>
``````

INHERITING CLASS: MallardDuck

``````<?php
class MallardDuck extends Duck
{
function MallardDuck()
{
\$this->quackable = 1;
\$this->swimmable = 1;
}

function display()
{
echo "A Mallard Duck Looks Like This<BR/>";
}
}
?>
``````

INHERITING CLASS: WoddenDecoyDuck

``````<?php
class WoddenDecoyDuck extends Duck
{
function woddendecoyduck()
{
\$this->quackable = 0;
\$this->swimmable = 0;
}

function display()
{
echo "A Wooden Decoy Duck Looks Like This<BR/>";
}
}
``````

Imran

• #### What is difference between Interaction design, Visual Design, Web design, UX design, UI design, UI d

as seen on Stack Overflow - Search for 'Stack Overflow'
What is difference between Interaction design, Visual Design, Web design, UX design, UI design, UI development? BTB, link found below answered for UI Vs UX. http://stackoverflow.com/questions/1334496/difference-between-ui-and-ux >>> More

• #### The Incremental Architect&rsquo;s Napkin - #5 - Design functions for extensibility and readability

as seen on Geeks with Blogs - Search for 'Geeks with Blogs'
Originally posted on: http://geekswithblogs.net/theArchitectsNapkin/archive/2014/08/24/the-incremental-architectrsquos-napkin---5---design-functions-for.aspx The functionality of programs is entered via Entry Points. So what we´re talking about when designing software is a bunch of functions handling… >>> More

• #### Logo Design Online: Process Of Hiring And Working With An Online Logo Design Company

as seen on Article City - Search for 'Article City'
Hiring an online logo design company is not easy these days; you will find hundreds of logo design companies on just click of a mouse. But it';s up to your decision making skills how you select a best... [Author: Gisselle Gloria - Web Design and Development - October 05, 2009] >>> More

• #### OO Design - polymorphism - how to design for handing streams of different file types

as seen on Stack Overflow - Search for 'Stack Overflow'
I've little experience with advanced OO practices, and I want to design this properly as an exercise. I'm thinking of implementing the following, and I'm asking if I'm going about this the right way. I have a class PImage that holds the raw data and some information I need for an image file. Its… >>> More

• #### Is there any guidelines to convert Table design to Div design keeping same cross browser compatible

as seen on Stack Overflow - Search for 'Stack Overflow'
Is there any guidelines to convert Table design to Div design keeping same cross browser compatible layout? >>> More

• #### Terminology: Difference between software interface, software component, software unit, software modu

as seen on Stack Overflow - Search for 'Stack Overflow'
I see these terms used quite a lot between various authors, but I can't seem to fix upon definitive definitions. From my POV a software interface is a "type" specifying the way in which a software component may be used by other softare components. But what exactly a software component is I'm not… >>> More

• #### Miracle Traffic Bot - A Multi Use SEO Software - Why One Should Choose Multi Use Software

as seen on Ezine Articles - Search for 'Ezine Articles'
Miracle traffic bot SEO software like so many products online it can be a scam. It claims to be wonderful, that I was thinking before I buy this product. They call it the 3-in-1 SEO magic software. >>> More

as seen on Stack Overflow - Search for 'Stack Overflow'
I'm primarily a web app developer/entrepreneur, so there's a lot I don't know about the desktop software distribution process. I've been thinking about making a Mac OS X app for fun, that I would distribute for free or a really small donation, but started thinking about distribution+download analytics: a)… >>> More

• #### software cd that allow to install software only once [closed]

as seen on Stack Overflow - Search for 'Stack Overflow'
i have a installation cd of one software that allows me to install that software only once in a life. after formatting or even trying to install that software in another pc, cd doen't allow me install that software. i want to know what is the mechanism that make such a cd. And how to crack that installation… >>> More

• #### What software license to use for commercial software?

as seen on Stack Overflow - Search for 'Stack Overflow'
Hey there, Under what license agreement should you release software under if it's closed-source and for commercial use only? Are there multiple license types? (such with open source you have BSD, GNU/GPL etc..) If so, which one do I choose, and are there samples out there to get you started? I… >>> More