Question: I have been trying to implement the State Pattern into my Library UML and I am not sure if I am on the right track.

I have been trying to implement the State Pattern into my Library UML and I am not sure if I am on the right track. I have 6 states for showing the availability of an Item to help the Librarian find them. For context there are 3 guidelines which I have already implemented, however I am not 100% confident if I did it right:

1. Only SHELF state can loan and display.

2. DISPLAY, OUT, REPAIR states can RETURN but each goes to a different state

3. Return shelves

(The 6 states are SHELF, DISPLAY, OUT, RETURN, REPAIR, DISCARD)

First, here is a drawing of how I think the State flow will be based on the guidelines above (I apologize I couldn't flip it around):

I have been trying to implement the State Pattern into my Library

Here is my State UML Diagram. My "Context" Class is the Item Class and I created an instance variable to hold its current State.

I am unsure about which methods to add to each State. I think each state needs +getItem() and certain States, such as "OutState" would need +getOnLoanIndicator() to update when the Item has been borrowed. I am just not sure about the State classes themselves, I feel as though I have implemented them incorrectly. Any feedback and advice is much much appreciated as I have been stuck on this for a while! Thank you!

UML and I am not sure if I am on the right

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!