Lecture w11 01 Adapter Facade Tutorial PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Adapter Pa*ern

Suppose that you have an applica6on for playing sounds with the following interfaces and
classes

• A MediaPlayer interface that has the play method that takes file name as a parameter

• A concrete class MP3 implemen6ng the MediaPlayer interface. MP3 can play mp3
format audio files by default.

• The applica6on is extended to support other audio formats.

• Another interface MediaPackage, this interface has playFile method which takes
file name as a parameter

• and concrete classes implemen6ng the MediaPackage interface were added.


These classes can play vlc (name the class VlcPlayer) and mp4 (name the class
Mp4Player) format files.

• Using the adapter pa*ern show how to make MP3 to play other formats as well.

• Note: in the implementa6on of the play or playFile methods, use a proper prin6ng
statement to indicate what is happening

• Write a Main class to demo how to use MP3 class to play various formats.
Façade Pa*ern

The theater example that we studied in the lecture of façade pa*ern is given in the folder
façade_source_code on the moodle. Download the source code and create a new Java project,
add the classes you downloaded to the project. The following classes in the folder {Aplifier,
CdPlayer, DVdPlayer, PopcornPopper, Projector, Screen, TheaterLights, and Tuner} are classes of
system that combined in different ways support the following func6onali6es
• Watch movie

o Popper on , popper pop, lights dim to 10, screen down, projector on, put the
projector on wide screen mod, amplifier on, amplifier is set to DvD, on amplifier
set surrounding sound and set volume to 5, for the DvdPlayer set it to on and set
to play the given movie as parameter passed to the WatchMovie method
• End movie

o Popper off, lights off, screen up, projector off, amplifier off, dvd stop, dvd eject,
dvd off
• Listen to Cd

o Lights on, amplifier set on and set volume to 5, and set to Cd and set surrounding
stereo, for the Cd set on and play the given cd 6tle as parameter
• End cd

o Amplifier off, eject the cd, finally Cd off


• Listen to radio

o The method takes double frequency as parameter. Set the tuner to on, set tuner
to given frequency, amplifier is set to on, set volume to 5, on amplifier set tuner
to tuner
• End radio

o Tuner off and amplifier is off

The Façade interface simplifies the way to interact with the system to the following
func6onali6es: WatchMovie, EndMovie, ListenToCD, EndCD, ListenToRadio, EndRadio. The steps
to do each one of these func6onali6es in given in the code of the HomeTheaterFacade. In the
driver class “HometheaterTestDrive” add all necessary code
• to watch a movie, then end the movie
• listen to radio, end listening to radio
• listen to CD, end CD

You might also like