rgb192
asked on
strategy pattern: Undefined variable: Workers
<?php
class Bob
{
public function DoYourJob()
{
$H = new Hammer();
$N = new Nails();
$W = new WoodPlanks();
$this->_buildDesk($H, $N, $W);
}
private function _buildDesk($Hammer,$Nails,$WoodPlanks)
{
echo'<br>... code that builds a desk ...';
}
}
class Jerry
{
public function DoYourJob()
{
$C = new Car();
$C->DriveTo("123 Main Street");
}
}
class WorkForce
{
public $Workers = array();
public function GoToWork()
{
foreach($Workers as $Worker)
{
$Worker->DoYourJob();
}
}
}
$WF = new WorkForce();
$WF->Workers[] = new Bob();
$WF->Workers[] = new Jerry();
$WF->GoToWork();
?>
Notice: Undefined variable: Workers in C:\wamp\www\test\gStrategy
Warning: Invalid argument supplied for foreach() in C:\wamp\www\test\gStrategy
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
Sorry, I was on vacation. The strategy part of it isn't just the word"if" - strategy patterns just indicate conditional processing in general - that the SAME bit of code can be executed DIFFERENTLY based on the conditions and parameters.
ASKER
SAME bit of code can be executed DIFFERENTLY based on the conditions and parameters.
thanks for clarification
ASKER
Open in new window
output
... code that builds a desk ...Okay, we're driving to 123 Main Street
where is the strategy
I thought strategy was 'if statement'
how is code different 'if something' happens