Update README.md
Co-authored-by: LucasCatolino <lcatolino@fi.uba.ar> Co-authored-by: KuJo7 <joel.k2010@gmail.com>
This commit is contained in:
parent
42f64f0e57
commit
75674b4439
|
@ -192,3 +192,5 @@ nb-configuration.xml
|
|||
## Miscellaneous
|
||||
##############################
|
||||
*.log
|
||||
|
||||
*.png
|
||||
|
|
50
README.md
50
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
|
||||
|
||||
- ...
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.util.List;
|
|||
public class Library {
|
||||
private static Library instance;
|
||||
private final List<LibraryItem> libraryItems;
|
||||
private int booksCapacity = 100;
|
||||
private int booksCapacity = 3;
|
||||
|
||||
public Library() {
|
||||
this.libraryItems = new ArrayList<>();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue