This application uses the classic computer science example of a bookstore. It is implemented as a console based application. It's a work in progress, but it's already apparent that something needs cleaning. The BookService
that is the core of the application has two responsibilities: interact with the database and manage caching of those values. This leads to both a complicated implementation and complicated tests.
- Refactor the implmentation to split the database and cache responsiblities into two classes and compose them using the decorator pattern. (Decorate the database class with the cache class)
- Add a profiler decorator to the
BookService
that logs how long service calls take to complete. - Compose your decorators so that both the database class and cache class have profiler decorators. If you did part 1 and 2 correctly you should only have to change the
BookServiceFactory
class.
The bookstore was written using Java 8 (but should be compatible with Java 1.6 and up). Maven is used as the build tool. It was designed to be runnable on the commandline, so it has no dependencies on any particular IDE. You are free to choose your favorite IDE or hack in the terminal.
The project depends on the following projects. You shouldn't have to do anything to install them. Maven will take care of everything.
Before you can do anything, you will need to run this script to create an Sqlite database with some sample data and second Sqlite database that will be used for testing.
mvn compile exec:java@init
mvn test
mvn package exec:java@main
This project does not necessarily represent the best way to interact with a database, cache, or logger in Java. It is intended to be a simple example where the decorator pattern can be applied.