Factory Method Lab 1
Lab: Extending the Document Management System
Objective:
In this lab, you will extend the provided Document Management System application by adding a new document type.
Instructions:
Review the provided Document Management System application. This application currently supports creating and opening Word and PDF documents through the use of a Factory Method pattern.
Add a new document type:
ExcelDocument
. This will require creating a new class,ExcelDocument
, which implements theDocument
interface.The
ExcelDocument
class should override theopen()
method. The method should print "Opening Excel document..." to the console.
Create a new factory class:
ExcelDocumentFactory
. This class should extendDocumentFactory
.The
ExcelDocumentFactory
class should override thecreateDocument()
method. The method should return a new instance ofExcelDocument
.
Update the
Client
class to demonstrate the use of theExcelDocumentFactory
. It should create anExcelDocument
using theExcelDocumentFactory
and call theopen()
method on it.Test your application to ensure it behaves as expected.
Tips:
Remember, the Factory Method pattern is about creating an interface for creating objects, but letting subclasses decide which class to instantiate.
Submission:
You should submit your completed Java files for Document
, WordDocument
, PdfDocument
, DocumentFactory
, WordDocumentFactory
, PdfDocumentFactory
, Client
, ExcelDocument
, and ExcelDocumentFactory
.
Remember, the goal of this lab is to understand the Factory Method pattern and how it can be used to provide a flexible interface for creating new objects. Good luck!