Adapter pattern works as a connection between two incompatible interfaces. This type of design pattern comes under structural pattern as this model combines the ability of two dependent interfaces.
This pattern involves a single class which is responsible to join functionalities of independent or incompatible interfaces. A real life instance could be a case of card reader which acts as an adapter between memory card and a laptop. You plug-in the memory cards into card reader and card reader into the laptop so that memory card can be study via laptop.
We are demonstrating use of Adapter pattern via following instance in which an audio player device can play mp3 files only and wants to apply an advanced audio player able of playing vice and mp4 files.
We contain a Media Player interface and a valid class AudioPlayerimplementing the Media Player interface. Audio Player can play mp3 format audio files by payment.
We are having a different interface AdvancedMediaPlayer and real classes implementing the AdvancedMediaPlayer interface. These classes can play vice and mp4 arrangement files.
We want to create Audio Player to play other formats as well. To attain this, we have formed an adapter class Media Adapter which equipment the Media Player interface and uses AdvancedMediaPlayer substance to play the essential format.
Audio Player uses the adapter class Media Adapter momentary it the desired audio kind without knowing the actual class which can play the wanted format. AdapterPatternDemo, our presentation class will apply Audio Player class to play various formats.
Create interfaces for Media Player and basic Media Player.
Create real classes implementing the AdvancedMediaPlayer interface.
Create adapter class implement the Media Player line.
Construct concrete class implementing the Media Player boundary.
Apply the Audio performer to play dissimilar type of audio format.
Verify the output.
Design Patterns Related Interview Questions
|Java Script Interview Questions||AJAX Interview Questions|
|Graphic Design Interview Questions||Adobe Indesign Interview Questions|
|Java-Multithreading Interview Questions||Database Design Interview Questions|
|Compiler Design Interview Questions||CSS Advanced Interview Questions|
|Java Design Patterns Interview Questions||Hardware design Interview Questions|
|Material Design Lite Interview Questions||Object Oriented Analysis and Design Interview Questions|
|Standard Template Library (STL) Interview Questions|
Design Patterns Tutorial
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.