All 7 requirements completed. The NotesApp program includes following operations:
- Multiple types of notes: This program supports three kinds of nots——
TextNote(plain text note),TodoListNote(users can add tasks and mark them as done by ticking them off),MultimediaNote(Combination of images, hyperlinks and text) - Subjects/Categories: Users can create custom subjects for organizing their notes(e.g., an academic discipline, a university module, a meeting minutes, etc.) Selecting a subject from the sidebar will display all notes under that category.
- Search and Sorting: Users can search for notes by
titleorcontent(To-Do List notes can be searched bytasks, while Multimedia Notes can be searched bydescriptions.) and sort them by creation time, last modified time, or title in both ascending and descending order. - AutoSave: When users create or edit a TextNote, any modifications, including changes to the title, subject, or content, are automatically saved and recorded in a local JSON file—no need to click a save button.
- The Recycling Bin System: Users can move unused notes to the trash, hiding them from the note list (while keeping them stored locally). They can then choose to recover or permanently delete the notes from the trash.
- A clean frontend page: A web page built with basic HTML, CSS, and JavaScript, offering an intuitive design, logical layout, and smooth user interaction.
Stage 1: Defined the Entities:
- Defined
Noteas abstract class to encapsulate common attributes (e.g.,title,subject,modifiedTime) and methods, then implementedTextNote,TodoListNote, andMultimediaNoteas concrete implementations, each adding type-specific fields. - Defined enumeration
NoteTypeto map note types to classes and suffixes, including utility methods (e.g.,fromNote,fromSuffix) for type resolution. This reinforced polymorphism and type safety.
Stage 2: Defined the Model Layer and Utility Classes:
- Implemented
ModelFactoryto provide a singletonModel, using aHashMap<String, Note>(noteBook)and aList<String>for subjects, then added basic methods likecreateNote,updateNote,findNoteById. - Defined
JsonUtil,TimeUtil,ImageUtilclasses for data persistence and completely isolated them from the usage scenarios, ensuring easier future use. - Developed auxiliary models,
FileModel(for JSON persistence withJsonUtil),TrashModel(fortrash management), andQueryModel(for sorting and searching) to further separate concerns and improve maintainability.
Stage 3: Implemented the Controller Layer:
- Created an abstract
BaseServletwith reflection-based URI mapping (e.g.,/crud/createNotetocreateNote), abstracting request handling. - Based on different operations categories, implemented
NoteCrudServlet(for creating and updating, etc),NoteTaskServlet(for searching and sorting),NoteLoadServlet(for loading notes list and form pages), pre-defined the communication rules between the View layer and completed the part of interaction with the Model layer.
Stage 4: Developed the View Layer:
- Created the basic form in
TestNote.jsp,todoListNote.jsp,multimediaNote.jspbased on the data needed by the controller layer. - Coordinated the interaction between the Controller layer and the View layer, organized the webpages execution and routing logic.
- Completed
NoteList.jsp,searchNote.jsp, the part of the View layer that retrieves and displays data from the Controller layer. - Improved the page interaction logic using JavaScript and enhanced the content layout and appearance with CSS.
Robust abstraction through the Note and BaseServlet abstract classes, which provided a foundational framework for extensibility and enabled polymorphism and reduced code duplication. The enumeration NoteType further enhanced this by formalizing note types, while utility classes abstracted low-level operations such as JSON parsing and image saving. This layered abstraction allowed high-level logic in servlets to remain clean and focused, minimizing complexity in business logic implementation.
Encapsulation is reinforced by Note subclasses hiding type-specific data and Model concealing persistence details behind a clean interface. The controller’s process of encapsulating frontend data into a structured object (a Note instance) before passing it to the model shields the model from raw data complexity. Private fields like noteBook in Model and invokeMethod in BaseServlet safeguard internal state, promoting data integrity and providing controlled access through well-defined APIs.
Within Model, methods like createNote and getAllNotes work cohesively towards data management, ensuring internal elements are tightly related. Each class is designed for a single, well-defined purpose: Model centralizes data coordination, JsonUtil focuses on JSON parsing and writing, and TimeUtil defines timestamp formatting. The Model further supports SRP by delegating to auxiliary models like FileModel and TrashModel, preventing overburdening and ensuring a modular design.
The application supports the Open-Closed Principle (OCP) by allowing new note types to extend Note and update NoteType without altering existing code. BaseServlet accommodates new endpoints via method addition, and utility classes are reusable.
I worked diligently on this coursework and believe I achieved excellent results. I successfully applied the object-oriented programming principles discussed above in the Model and Controller layers. The View layer’s frontend code might be a bit messy, but it ultimately achieved a highly satisfactory outcome.