From 75674b4439ee8e6113663c4ddea03dcfbaa004ce Mon Sep 17 00:00:00 2001 From: Santiago Lo Coco Date: Sun, 25 Feb 2024 16:09:44 +0100 Subject: [PATCH] Update README.md Co-authored-by: LucasCatolino Co-authored-by: KuJo7 --- .gitignore | 2 + README.md | 50 ++++++++++++++++++++++- test/src/main/java/edu/uastw/Library.java | 2 +- test/src/main/java/edu/uastw/Test.java | 11 ++++- 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 6746c8d..689cf45 100644 --- a/.gitignore +++ b/.gitignore @@ -192,3 +192,5 @@ nb-configuration.xml ## Miscellaneous ############################## *.log + +*.png diff --git a/README.md b/README.md index e2e8b64..1ce25ad 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,50 @@ -## ADP Homework +# Library System with Design Patterns +This is a simple Java project demonstrating a library system that utilizes various design patterns including builder, singleton, decorator, and iterator. + +## Overview + +The project consists of the following components: + +- **Book:** Represents a book in the library. +- **Magazine:** Represents a magazine in the library. +- **LibraryItem:** An interface representing items in the library, implemented by both Book and Magazine classes. +- **Library:** Implements the singleton pattern and represents the library. It manages the collection of items (books and magazines) and supports adding items with a capacity constraint. It also implements the iterator pattern to provide a way to iterate over its items. +- **LibraryBuilder:** Implements the builder pattern to construct the library by adding books and magazines. +- **LibraryDecorator:** An abstract class for extending functionality of the Library. +- **IncreaseBooksCapacityDecorator:** A concrete decorator to increase the books capacity of the Library. +- **DecreaseBooksCapacityDecorator:** A concrete decorator to decrease the books capacity of the Library. +- **Test:** Contains the main method to demonstrate the library system. + +## Design Patterns Used + +- **Builder Pattern:** Used in the LibraryBuilder class to construct the library by adding books and magazines. +- **Singleton Pattern:** Implemented in the Library class to ensure only one instance of the library exists throughout the application. +- **Decorator Pattern:** Implemented with LibraryDecorator and its concrete decorators (IncreaseBooksCapacityDecorator and DecreaseBooksCapacityDecorator) to extend the functionality of the Library dynamically. +- **Iterator Pattern:** Implemented in the Library class to provide a way to iterate over its collection of items. + +## Prerequisites + +Before you begin, ensure you have met the following requirements: + +- Maven version 3 or higher +- Java version 11 or higher + +## Usage + +To run the project: + +1. Clone or download the repository to your local machine. +2. Open the project in your preferred Java IDE. +3. Run the Test class. + +The Test class demonstrates the following functionalities: +- Creation of books and magazines. +- Adding items to the library. +- Displaying items in the library. +- Modifying the books capacity using decorators. +- Iterating over the library items using the Iterator pattern. + +## Contributors + +- ... diff --git a/test/src/main/java/edu/uastw/Library.java b/test/src/main/java/edu/uastw/Library.java index 29f98fe..3ba2c69 100644 --- a/test/src/main/java/edu/uastw/Library.java +++ b/test/src/main/java/edu/uastw/Library.java @@ -6,7 +6,7 @@ import java.util.List; public class Library { private static Library instance; private final List libraryItems; - private int booksCapacity = 100; + private int booksCapacity = 3; public Library() { this.libraryItems = new ArrayList<>(); diff --git a/test/src/main/java/edu/uastw/Test.java b/test/src/main/java/edu/uastw/Test.java index af5eb88..85e8ce6 100644 --- a/test/src/main/java/edu/uastw/Test.java +++ b/test/src/main/java/edu/uastw/Test.java @@ -16,14 +16,21 @@ public class Test { library.displayLibraryItems(); - LibraryDecorator increasedCapacityLibrary = new IncreaseBooksCapacityDecorator(library, 50); + LibraryDecorator increasedCapacityLibrary = new IncreaseBooksCapacityDecorator(library, 1); increasedCapacityLibrary.extendedFunctionality(); + library.addLibraryItem(magazine1); + library.displayLibraryItems(); + System.out.println("Modified books capacity: " + library.getBooksCapacity()); - LibraryDecorator decreasedCapacityLibrary = new DecreaseBooksCapacityDecorator(library, 30); + LibraryDecorator decreasedCapacityLibrary = new DecreaseBooksCapacityDecorator(library, 2); decreasedCapacityLibrary.extendedFunctionality(); System.out.println("Modified books capacity: " + library.getBooksCapacity()); + library.displayLibraryItems(); + + library.addLibraryItem(magazine1); + library.displayLibraryItems(); } } \ No newline at end of file