I need to design an application that resembles an internal mailing system. However, this is just a course project. No networking required. The professor is just making us put the discussed data structures to work. However, I have been having trouble deciding how to design the application. Let me explain briefly what I have to do and then I will share my thoughts.
I think it would be a good idea if let you know that this is a command line based application. No GUI involved.
The internal mail system consists of 5 different possible states. General, Administrator, User, Moderator, and Compose. It is possible to be only at one state at a time. When the application starts, it enters the General state by default. The only possible command in this state is to log in to some other account (User, Admin, Mod.) The User has basic commands like reading his messages, sending (compose) new ones to some other user, deleting messages, logging out, and a couple more. A User can change to one of two states: Compose or General. To get to the Compose state, the User must use the command compose
. In this state you compose a message to some other user. Once you finish composing the message you go back to the User state. The only way a User could go back to General is by logging out.
Admin (which inherits the behavior of User) and Mod are pretty much the same. They can change states as well.
Here's a summary of how it is possible to change state
General |----->Admin
| |---->User(limited)
| |---->Compose
|
|----->Moderator
|
|----->User
| |---->Compose
I'm a new to design patterns. I've been reading a lot about them lately. However, this will be the first time I'll implement them. If one of my suggestions seem weird please let me know.
The State Pattern seems like a great idea. I lets me change an object state dynamically. However, not all states have the same methods. Administrators has more methods than User. Moderator does not have any of the methods from Admin or User. You can only use General to log in. I think that this will then limit the ability to use State Pattern. Do you have any suggestions for some other pattern?
Another idea I had was something like the following. Since I can ascend and descend states, I could be seen as a stack. For example: a user that is in compose mode.
\ /
| Compose | <---- top (current state)
| User |
| General |
-----------
Do you have any ideas on how I could implement that? Is it even possible? Although I'm comfortable with Java the most, C++ or pseudo code is fine.
Thank you very much.