Answered step by step
Verified Expert Solution
Question
1 Approved Answer
readme.txt Use the Adapter pattern to modify and create the necessary classes so the VideoSocket class uses HDMIPlug's digitalDisplay() implementation instead of VGAPlug's display() method
readme.txt
Use the Adapter pattern to modify and create the necessary classes so the VideoSocket class uses HDMIPlug's digitalDisplay() implementation instead of VGAPlug's display() method when calling its VideoPlug's display() method. Note that you cannot simply create and use an HDMIPlug in VideoSocket. You must use an implementation of the VideoPlug interface. Follow any directions in the code comments.
HDMIPlug.pseudo
// DO NOT MODIFY THIS CLASS | |
// notice that this class does not implement VideoPlug | |
public class HDMIPlug { | |
public int width = 1920; | |
public int height = 1080; | |
// constructor | |
public HDMIPlug(){}; | |
// the actual method we want to run | |
// notice it does not take the same parameters | |
public digitalDisplay(){ | |
print "Displaying a " + width + " by " + | |
height + " digital image!"; | |
} | |
} |
VGAPlug.pseudo
// DO NOT MODIFY THIS CLASS - what if we need to use it elsewhere? | |
public class VGAPlug implements VideoPlug{ | |
// constructor | |
public VGAPlug(){}; | |
public display(int width, int height){ | |
print "Displaying a " + width + " by " + | |
height + " analog image!"; | |
} | |
} |
VideoPlug.pseudo
public interface VideoPlug { | |
public display(int width, int height); | |
} |
VideoSocket.pseudo
// Modify this class so it uses the HDMIPlug's | |
// digitalDisplay() implementation. Note that you | |
// still must use a VidePlug (i.e., don't just replace | |
// plug with an HDMIPlug object. | |
public class VideoSocket { | |
public main(){ | |
// plug MUST be of type VideoPlug | |
VideoPlug plug = new VGAPlug(); | |
// call plug.display() | |
plug.display(1024, 768); | |
// use plug in a method which only takes objects | |
// of type VideoPlug (i.e., it can't take HDMIPlugs) | |
// This line MUST be run on the plug | |
someOtherClass.plugDiagnostic(plug); | |
} | |
} |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started