Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[Java] [Memento Pattern] In-Memory Database with Persistence 1. We will create an in-memory database for a bookstore inventory. The bookstore sells books. Each book has

[Java] [Memento Pattern] In-Memory Database with Persistence

1. We will create an in-memory database for a bookstore inventory. The bookstore sells books. Each book has a name, price, unique id and a quantity. The store uses sequential integers for unique ids. We need to be able to

Add new books.

Sell a book in the inventory.

Add new copies of existing books

Change the price of a book

Find the price and/or quantity of a book by either name or id.

Create an Inventory class to keep track of the store inventory.

2. Use thememento patterntocopy the datain an Inventory object. Make the memento serializable so it can be saved in a file. Given an Inventory object and a memento you can restore the Inventory object to a previous state.

So now we can periodically create and save a memento of the Inventory object.

3. For each operation that changes the state of the Inventory object creates a command. Make the commands serializable.

Now every time we perform an operation on an Inventory object, we can create a command, perform the command and save the command to disk. This way we will have a history of all the operations. If our program were to crash we can recover the last state by first loading the last memento and then replaying all the commands done since the last memento was created.

4. Create a decorator for Inventory objects. For every operation that changes the Inventory object's state, the decorator will create the command, perform the command and save the command to a file.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data And Hadoop Fundamentals Tools And Techniques For Data Driven Success

Authors: Mayank Bhushan

2nd Edition

9355516665, 978-9355516664

More Books

Students also viewed these Databases questions

Question

b. Explain how you initially felt about the communication.

Answered: 1 week ago

Question

3. Identify the methods used within each of the three approaches.

Answered: 1 week ago

Question

a. When did your ancestors come to the United States?

Answered: 1 week ago