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:

  1. 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.

  2. Add a new document type: ExcelDocument. This will require creating a new class, ExcelDocument, which implements the Document interface.

    • The ExcelDocument class should override the open() method. The method should print "Opening Excel document..." to the console.

  3. Create a new factory class: ExcelDocumentFactory. This class should extend DocumentFactory.

    • The ExcelDocumentFactory class should override the createDocument() method. The method should return a new instance of ExcelDocument.

  4. Update the Client class to demonstrate the use of the ExcelDocumentFactory. It should create an ExcelDocument using the ExcelDocumentFactory and call the open() method on it.

  5. 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!