A: 

What do you think about a Model - ModelMapper arch? Zend Framework uses this approach. You could have possibily the following classes: (silly naming convention for better understanding)

  • Model_User
  • Mapper_User_Email
  • Mapper_User_Name
  • Mapper_User_Password

And the individual mappers read the needed data, the 3rd party class only calls Model_User->getName()

Edit: Example usage:

//simple code:
$user = new Model_User();
echo "Your name is: " . $user->getName();

//Model_User:
public function getName() {
    if($this->_name = null) {
        $this->getNameMapper()->getName($this);
        //getNameMapper() returns a Mapper_User_Name object
    }
    return $this->getName();
}   

//Mapper_User_Name:
public function getName($user) {
    $name = "john"; /*magic here, the class communicate with the service that holds names*/
    $user->setName($name);
}

Example only, the getters and setters could be more defensive.

erenon
do you suggest (just to make sure) that I could create objects based on their property (i.e. an object to handle all operations for a User and another object which handles operation of a Group).. have i understood correct ?thanks for your input!
Jason
@Jason: see my edited post
erenon
+1  A: 

Eep! Firstly, since these are so similar, they should share a common base class or use an interface:

interface WebService {
    function createUser($username, $password);
    function deleteUser($username, $password);
    function createGroup($groupname);
    function deleteGroup($groupname);
}

class MyService implements WebService {
    function createUser($username, $password) {}
    function deleteUser($username, $password) {}
    function createGroup($groupname) {}
    function deleteGroup($groupname) {}
}

Secondly, I hope your services aren't actually called 1,2,3. If they are, that suggests to me that maybe you should be using some form of an array.

I don't like your idea of a "proxy" class. Are you always using all 3 services, or is this some sort of library where you just include the service you need? You haven't provided enough info about what you're actually trying to accomplish.

Mark
A: 

I would take a completely different approach. A REST interface would be perfect for what you're trying to do, which are the standard CRUD commands.

dj_segfault
The communication between the servers is implemented by the specific classes already listed by the author and is independent of the nature of the question. The author is looking for a method of managing three separate interfaces for three different servers, not looking for a new communication medium or protocol.
mattbasta
A: 

I like the idea of keeping each server's implementation in a separate class, and I also like Mark's idea of utilizing an interface. I'm also fond of your idea of a proxy class, but not in the form that you presented. I would create a class that acts as a pool of sorts. Something like this:

class WebServicePool implements WebService {

    private $webServices = array();

    public function registerWebService($service) {
        if($service instanceof WebService)
            $this->webServices[] = $service;
    }

    function createUser($username, $password) {
        foreach($this->webServices as $service)
            $service->createUser($username, $password);
    }
    // ...
}

You could also use magic methods to proxy this functionality:

class WebServicePool {

    private $webServices = array();

    public function registerWebService($service) {
        if($service instanceof WebService)
            $this->webServices[] = $service;
    }

    function __call($name, $arguments) {
        foreach($this->webServices as $service)
            call_user_func_array(array($service, $name), $arguments);
    }
}

That way, if you add more functions to your interface, you won't need to update your pool class. Hope this helps!

mattbasta
A: 

I'm sorry.. I've lost access to my email account and the stackoverflow account.. I've created a new one, so I'll be posting my question again under a different username :(

You can find the new revised question (I hope I've cleared all blurry parts) here: http://stackoverflow.com/questions/2048022/design-question-which-is-better-practice-part-2

sorry for the inconvenience :(

Jason