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 {}
class dog extends animal {
function bark(){
// bark here
}
}
class cat extends animal {}
$dog = new dog();
$dog->bark();
abstract class animal {
function bark(){
// bark here
}
// bark here
}
}
class dog extends animal{}
class cat extends animal{}
$dog = new dog();
$dog->bark();
$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();
Comments
Post a Comment