Code Design Question
Let’s suppose I’m using a third party API class, oh, I don’t know, let’s say “Facebook.” I’ve got a $facebook=new Facebook; and $facebook->api_client->bar(), et cetera. And suppose, I want to do something with it, but I’m using a class too. Let’s say, I want a class “Pets.” I’ll need to use the facebook class for communicating with the facebook servers and configuring stuff.
Which is the “Best Practice”?
- extend the facebook class like “class Pets extends Facebook” …
- use a facebook variable in the Pets class – $pets=new Pets; $pets->fbook =& $facebook;
- Don’t tie the two objects together
What do you think results in the most clear code?

on June 14th, 2009 at 5:29 am
Erm, not that I can really read object-oriented PHP, but it seems to me that if you don’t have something that would be a direct descendant of the original object, that it shouldn’t be classed, or even made into a method. I vote for “don’t tie the two together”, unless of course, you intend to make a “Facebook” about “pets” (extension, which I assume is roughly translated as “inheritance”) or you want to have some property of pets that is a “Facebook” (facebook variable). So, yeah, don’t tie them.