Javafree
Página Inicial do Fórum > Design Patterns, UML e Arquitetura

Padrao Adapter



Criar novo tópico   Responder tópico


  1. rina_peli
    Posts:1


    Comment Arrow

    Publicado em: 24/10/2014 16:18:57

    Boa tarde,
    Comecei a estudar padrões de projetos e gostaria de saber se o codigo abaixo contempla o padrão adapter

    <?
    interface IInformationDisplay {
    public function subscribe();
    public function unsubscribe();
    public function sendUpdates();
    }


    class EmailNetWorkAdapter implements IInformationDisplay {

    private $objAdapter;

    public function __construct(RedesSociais $objAdapter) {
    $this->objAdapter = $objAdapter;
    }

    public function subscribe() {
    return $this->objAdapter->getRedeSocial();
    }

    public function unsubscribe() {
    return 'Un' . $this->objAdapter->getRedeSocial();
    }

    public function sendUpdates() {
    var_dump($this->objAdapter->sendMessage($this->objAdapter->getRedeSocial() . ' Ola', $this->objAdapter->getUser()));

    }
    }


    abstract class RedesSociais {
    abstract public function sendMessage($message, $user);
    abstract public function getUpdates();
    abstract public function getRedeSocial();
    }

    class TwitterService extends RedesSociais {
    private $username;
    public function setUser($username) {
    $this->username = $username;
    }

    public function getUser() {
    return $this->username;
    }

    public function sendMessage($message,$user) {
    return 'Message ' . $message . ' user: ' . $user;
    }

    public function getRedeSocial() {
    return 'Twitter';
    }
    public function getUpdates() {
    // Return Updates
    }
    }

    class FacebookService extends RedesSociais {
    private $username;
    public function setUser($username) {
    $this->username = $username;
    }

    public function getUser() {
    return $this->username;
    }

    public function sendMessage($message, $user) {
    return 'Message ' . $message . ' user: ' . $user;
    }

    public function getRedeSocial() {
    return 'Facebook';
    }
    public function getUpdates() {
    // Return Updates
    }
    }

    $objTwitter = new TwitterService();
    $objTwitter->setUser('rinaldo.peligrineli');

    $objAdapter = new EmailNetWorkAdapter($objTwitter);
    $objAdapter->sendUpdates();

    $objFace = new FacebookService();
    $objFace->setUser('teste.face');

    $objAdapter1 = new EmailNetWorkAdapter($objFace);
    $objAdapter1->sendUpdates();

    ?>"/>
    _________________

    Rinaldo Peligrineli



  1. Relacionados