Thursday, 5 February 2015

Refactoring: Push down method

Previously we mentioned the pull up method we can use during refactoring our code. The push down method is the exact opposite. Let's start with some code:

abstract class animal {
  function bark(){
    // bark here
  }
}
class dog extends animal{}
class cat extends animal{}

$dog = new dog();
$dog->bark();

Maybe one day our cat had a bark about it, or maybe we've coded an if statement to do something different like return false if it's a cat. 

abstract class animal {}
class dog extends animal {
  function bark(){
    // bark here
  }
}
class cat extends animal {}

$dog = new dog();
$dog->bark();

No comments:

Post a Comment

Lessons from Toyota: How 'True North' Can Transform Your Engineering Team

 In the realm of engineering, achieving excellence requires more than just technical proficiency; it demands a clear and unwavering vision. ...