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

Chrome Now Ships Every Two Weeks. Your Web Release Process Must Catch Up

Chrome 154 entered the stable channel on 22 September 2026. On its own, that is a routine browser update. What makes it strategically import...