php - Difference between abstract class extends and normal class extends -



is there clear difference why use abstract extends if can same in normal class excepts doesnt provide contract eg.

abstract class survivalneeds {  abstract public function eat(); // eats different foods work contract  public function breathe() {  // inhale o2 exhale co2 animals  }  } 

now

class human extends survivalneeds {    protected function eat() { //sometimes eat goat // contract             }  breathe()// extending having same functionality  inhale o2 , exhale co2    }  class goat extends survivalneeds{   protected function eat() { //wee eat greens // contract             }  breathe()// extending having same functionality  inhale o2 , exhale co2  } 

now same functionality can granted normal class extending except contract method , contract use interface also.

what saying correct inheritance works in both cases idea of abstract class common logic shared x classes extend functionality not instantiable self because doesn't make sense (maybe want have types of cars in system not generic car doesn't have brand)


Comments