This is a discussion on simulating object upcasting to an interface in PHP 4 within the PHP Language forums, part of the PHP Programming Forums category; In Java one is supposed to upcast an object to its interface whenever appropriate: MyInterface customers = new MySpecificClass(); The idea ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
In Java one is supposed to upcast an object to its interface whenever
appropriate: MyInterface customers = new MySpecificClass(); The idea is that if later one wants to change the specific implementation one only has to change a few lines, possibly just the one line above. Thus the code becomes more flexible. Is it right to say that there is no way to do this in PHP? I've taken to simulating the same by using one object as a mask that sets and then uses another object: myMaskObj = new MaskDatabase(); myMaskObj->setDbObj("DatabaseObject"); myMaskObj->query("SELECT * FROM content WHERE type='comments'"); MaskDatabase has a method called "query" which simply passes the query along to DatabaseObject which also has a method called query. Other ideas? |