A simple console-based BookStore system implemented in Java, demonstrating several classic software design patterns including Singleton, Builder, Observer (Publisher-Subscriber), Strategy, and Facade. This application allows users to register, subscribe for notifications, read books, and (for premium users) listen to audiobooks.
-
π Add new books to the bookstore (with title, author, and price).
-
π€ Register new users (standard or premium).
-
π¬ Subscribe/unsubscribe users for price update notifications.
-
π° Update book prices and automatically notify subscribers.
-
π Allow users to read books.
-
π§ Allow premium users to listen to audiobooks.
| Pattern | Purpose |
|---|---|
| Singleton | Ensure a single instance of BookStore throughout the application. |
| Builder | Simplify the creation of complex Book objects via a fluent interface. |
| Observer | Allow users to subscribe and receive notifications when book prices change. |
| Strategy | Define flexible behaviors for reading and listening to books for different user types. |
| Facade | Provide a simple, unified interface for interacting with the bookstore system. |
-
Clone the Repository
git clone https://github.com/yourusername/Simplified-Book-Store.git cd Simplified-Book-Store -
Compile and Run
javac Main.java java Main
-
Available Console Commands
-
createBook <title> <author> <price> -
createUser <user_type> <username>(user_type=standardorpremium) -
subscribe <username> -
unsubscribe <username> -
updatePrice <title> <new_price> -
readBook <username> <title> -
listenBook <username> <title> -
endβ to terminate the program
createBook Dune Herbert 20
createUser premium Alice
createUser standard Bob
subscribe Alice
updatePrice Dune 25
readBook Alice Dune
listenBook Alice Dune
listenBook Bob Dune
end
Output:
Alice notified about price update for Dune to 25
Alice reading Dune by Herbert
Alice listening Dune by Herbert
No access
.
βββ Main.java // Application entry point with command parser
βββ BookStore.java // Singleton bookstore with Observer logic
βββ Facade.java // Simplified interface for external interaction
βββ Book.java // Book class with Builder pattern
βββ User.java // User base class + StandardUser & PremiumUser
βββ ReadingBehavior.java, ListenBehavior.java
βββ CanRead.java, CanListen.java, CanNotListen.java // Strategy implementations
βββ Observable.java // Observer interface