Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

object-oriented approach advice

Status
Not open for further replies.

jay8abear

Programmer
May 9, 2013
6
US
Hello,

I'm building a website which connects several reporting APIs (like google analytics) and I want to write a centralized class which does stuff like saving the authentication tokens to the database, and then each API would simply extend these features for the specifics that the api is responsible for (like getting the number of visitors to a website and whatnot).

My goal is to make this system very expandable in the future while keeping the core functions very simple. I've used pre-built OOP before, but never actually written one of my own that's this complicated. What kind of approach do I need to take?

Here's one idea I have right now, in pseudocode....

Code:
class apiCore {
  public function saveAuthToken ($whichApi = '') {
     //query mysql which updates the user record with the token particular to the chosen api
  }
  public function makeUserAuthenticated() {
     $_SESSION['userIsLoggedIn'] = true;
  }
}

class googleAnalytics extends apiCore {
  public function saveAuthToken() {
     parent::saveAuthToken('google');
  }
  public function authenticate( $args...) {
     ///individual authentication script...
     if ($success == true)
        self::saveAuthToken();
        parent::makeUserAuthenticated();
     }
  }
}

$client = new googleAnalytics();
$client->saveAuthToken();

what I'm thinking is, by using the basic structure as shown above, every client would use the same naming conventions, which still performing its own operations pursuant to how each individual api is built, right?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top