Search Results

Search found 2 results on 1 pages for 'danip'.

Page 1/1 | 1 

  • Better solution then simple factory method when concrete implementations have different attributes

    - by danip
    abstract class Animal { function eat() {..} function sleep() {..} function isSmart() } class Dog extends Animal { public $blnCanBark; function isSmart() { return $this->blnCanBark; } } class Cat extends Animal { public $blnCanJumpHigh; function isSmart() { return $this->blnCanJumpHigh; } } .. and so on up to 10-20 animals. Now I created a factory using simple factory method and try to create instances like this: class AnimalFactory { public static function create($strName) { switch($strName) { case 'Dog': return new Dog(); case 'Cat': return new Cat(); default: break; } } } The problem is I can't set the specific attributes like blnCanBark, blnCanJumpHigh in an efficient way. I can send all of them as extra params to create but this will not scale to more then a few classes. Also I can't break the inheritance because a lot of the basic functionality is the same. Is there a better pattern to solve this?

    Read the article

  • Search and Replace in MVC

    - by danip
    What would be a good MVC/OOP/GRASP/SOLID structure for a search/replace functionality. Methods: search/searchNext/replace/replaceAll. I'm interested only in the PHP arhitecture and how a professional developer would implement this in it's OWN FRAMEWORK. What names would you use for the classes? What subfolders would you used in your MODEL folder? How would you connect the MODELS/CONTROLLER? This is just a arhitecture question to understand better the principles of good OOP in practice. My current implementation is very simplistic using a service model: /controller/SearchReplaceController.php /models/services/SearchReplaceService.php The problem with this is I know I'm breaking SRP in the service but I found this somehow acceptable. Also creating a service does not feel like the best solution for this.

    Read the article

1