How to access functions in extended classes efficiently?

Posted by nischayn22 on Programmers See other posts from Programmers or by nischayn22
Published on 2012-06-16T05:20:19Z Indexed on 2012/06/16 9:22 UTC
Read the original article Hit count: 182

Filed under:
|

In PHP I have classes as below

    class Animal {
//some vars
public function printname(){ 
echo $this->name;
}
}

class AnimalMySql extends Animal {
static public function getTableFields(){ 
return array();
}
}

class AnimalPostgreSql extends Animal {
static public function getTableFields(){ 
return array();
}
}

Now I have an object $lion = new Animal(); and I want to do

if($store == mysql)
//getTableFields from class AnimalMySql
else
//getTableFields form class AnimalPostgreSql

I am new to OOP and not sure what is the best way to call the method from the specific class P.S. Please leave a note with the answer to explain the efficiency of the approach

© Programmers or respective owner

Related posts about php

Related posts about object-oriented