- Apply the factory pattern
Use the factory design pattern to model a camera and the different types of cameras one could have:
- A Polaroid Camera
- A Digital Camera
- A Phone Camera
To fully implement the design pattern to model a camera, consider the following instructions and tips:
- Create a
Camera
interface. - The
Camera
interface should have a method calledtakePhotograph()
that returns nothing and takes no parameters. - Create concrete classes of
PolaroidCamera
,DigitalCamera
, andPhoneCamera
that implement theCamera
interface. - Create a
CameraFactory
to instantiate each of the different types ofCamera
objects.
To help you test your code, you can use the driver class CameraDriver
that
has already been written out for you:
public class CameraDriver {
public static void main(String[] args) {
Camera polaroid = CameraFactory.getCamera("POLAROID");
Camera digital = CameraFactory.getCamera("DIGITAL");
Camera phone = CameraFactory.getCamera("PHONE");
polaroid.takePhotograph();
digital.takePhotograph();
phone.takePhotograph();
}
}
Below is the expected output from executing the CameraDriver
class:
Taking a photo on my polaroid camera!
Taking a photo on my digital camera!
Taking a photo on my phone camera!