Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!