Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Weight
- {
- protected $weight;
- public function __construct($weight)
- {
- $this->weight = $weight;
- }
- public function gain($kilograms)
- {
- return new static($this->weight + $kilograms);
- }
- public function loose($kilograms)
- {
- return new static($this->weight - $kilograms);
- }
- }
- class GymMember
- {
- protected $name;
- protected $weight;
- public function __construct($name, Weight $weight)
- {
- $this->name = $name;
- $this->weight = $weight;
- }
- public function workoutFor(TimeLength $length)
- {
- if(!$length->inSeconds() > (40 * 60 ))
- {
- return 'Keep up the good work!';
- }
- $this->weight->loose(2);
- }
- }
- class TimeLength
- {
- protected $seconds;
- private function __construct($seconds)
- {
- $this->seconds = $seconds;
- }
- public static function Minutes($minutes)
- {
- return new static($minutes * 60);
- }
- public function inSeconds()
- {
- return $this->seconds;
- }
- public function inMinutes()
- {
- return $this->seconds / 60;
- }
- public function inHours()
- {
- return $this->seconds / 60 / 60;
- }
- }
- $gymMember = new GymMember('MTROBERT', new Weight(78));
- $gymMember->workOutFor(Timelength::minutes(45));
- var_dump($gymMember);
- public function workoutFor(TimeLength $length)
- {
- // ...
- $this->weight->loose(2);
- }
- $this->weight = $this->weight->loose(2);
- public function loose($kilograms)
- {
- $this->weight -= $kilograms;
- }
Add Comment
Please, Sign In to add comment