Skip to main content

Posts

Showing posts from February, 2014

Improving ...

Short account of what I did: - I signed up for Machine Learning Stanford course ( Link ); - I registered on AI&BigData conference in Odessa Link ; - I am trying to study Clojure. After studying Clojure I'll describe all troubles which I got during studying and I'll write about my impression of the conference too.

PHP Design Patterns - Strategy

Today I want to explain how to use strategy design pattern in PHP. I tried to use this pattern when I want decouple algorithms for calculating something at runtime. For example, we can dynamically changing methods which will be calculate price of some items using some logic. Create car, for example: namespace strategy; abstract class Item{ abstract function getPrice(); } class Car extends Item{ protected $price; public $name; protected $isTuned; public function __construct($name, $price, $isTuned){ $this->name = $name; $this->price = $price; $this->isTuned = $isTuned; } /** * @return bool */ public function isTuned(){ return $this->isTuned; } public function getPrice(){ return $this->price; } } Suppose we want to separate method which will calculate price with different strategies. Create interface which will be implemented in each strategy. namespace strategy; int