Facade Pattern – Design Pattern

facade

Intent of facade is to provide the ease of use to any library(subsystem) through a an interface/class.

The Facade Pattern provides a unifide interface to a set of Interfaces in a subsystem. Facade defines a higher level interface that makes the subsystem easier to use.

Here We can take example of a complex theater system. For playing a movie we may need to set a different programs of each subsystem, Now We can look at facade is some thing like that reduces steps in performing a task, rather than tuning each individual program to work.

In below example TheaterFacade object makes easier to operate programs.

<?php
class TheaterFacade {
    public $dvd, $music, $movie, $player;

    public function TheaterFacade(DVD $dvd, Music $music, Movie $movie, Player $player)
    {
        $this->dvd = $dvd;
        $this->music = $music;
        $this->movie = $movie;
        $this->player = $player;
    }

    public function playMovie($movieName)
    {
        $this->music->setMusic(7);
        $this->movie->setMovie($movieName);
        $this->player->play();
        ...
        ...
    }

    public function stopMovie()
    {
        $this->music->stopMusic();
        $this->player->stop();
        ...
        ...
    }

}

class Music {
    
    public function setMusic($volume)
    {
      //setting volume function
    }

    public function stopMusic()
    {
      //stop function
    }
}

class Player {
    public function play(){
       //play function
    }

    public function stop(){
       //stop player function
    }

}

class Movie {

    public function setMovie ($movie) {
        //set movie to play
    }
}

2 Responses to Facade Pattern – Design Pattern

  1. Brigid Geurts says:

    hi!,I like your writing so so much! proportion we be in contact more about your article on AOL? I require an expert in this space to resolve my problem. May be that is you! Having a look ahead to see you.

  2. Su Potratz says:

    Nice post. I learn one thing more difficult on completely different blogs everyday. It should at all times be stimulating to read content material from different writers and practice somewhat one thing from their store. I’d prefer to use some with the content material on my weblog whether you don’t mind. Natually I’ll give you a link on your net blog. Thanks for sharing.

Leave a Reply

Your email address will not be published. Required fields are marked *