Assignment 2 Class and State Diagrams
Lesson 2 How to Create a State Diagram
OnlineOrder Class An online Order might be in the states Order Placed, Processing, Shipped, Ready for pickup, Picked up
PizzaOrder Class A pizza order might be in the states of Building, Assembling, Baking, Quality Checking, Delivering, Delivered
Bank Class A bank might be “solvent” or “insolvent”
StudentApplication Class A student application might be “pending”, “approved”, “rejected”
A CheckingAccount is an account offered as a service at a bank Preliminary attributes are listed as private (-) to the class and this means that only the methods of the class can access them Preliminary data types (character, float) listed for the class may be changed later Preliminary methods listed are public (+) and can be accessed by other classes Standard getter/setter (accessor/mutator) methods are not shown. These methods get or change attributes and are assumed at this point
class CheckingAccount Draft Class
CheckingAccount
- accountNumber: char - accountT ype: char - accountStatus: char - balance: float - dateOpened - dateClosed
+ Create() + deposit(amount: float) + withdraw(amount: float) + close(): refund + delete()
1. Select the classes that will require a state diagram. These classes should be ones that have complex behavior. Not all classes will require a state diagram.
Start with CheckingAccount
2. Identify the status conditions for each state. You can review other project documents, search for related class states, brainstorm, or use other techniques. Consider how the object is created and how it ceases to exist. Is it in an active or passive state, open or closed, pending, in preparation, scheduled, delivered, or other states.
For our CheckingAccount class, we identify the possible states as New, Open, Closed, Overdrawn
3. Identify the transitions that will cause the object to go to another state. Build the state diagram by starting with one of the states and identifying the transitions that will cause the object to go to another state.
See the state analysis table
4. Start building the state diagram and filling in the transitions and states. Make certain that they are in the correct order.
5. Look for independent, concurrent paths. An object may be in two states concurrently and it may be that the paths are independent and can change without affecting each other. Also look for states that are a composite state with one state inside another. 6. Identify any additional transitions. It may take several iterations to complete a state diagram. 7. Fully specify the transition to include message events, guard condition, or action expressions.
8. Review and test.
Use desk checking to test Are these really states for CheckingAccount? Is there a life cycle from Start to Final state? Are exceptions handled? Is there concurrent behavior or nested paths?
State Event Causing a Transition Out Resulting New State/Comment
Start Create() New
New deposit(amount) [amount >= 1]/increaseBalance Opened (The bank business rules require that a new account needs to have a minimum balance of $1 in order to be opened.)
Opened deposit(amount/increaseBalance Opened (Any deposits result in staying in the Opened state)
Opened withdraw(amount) [amount <= balance] decreaseBalance Opened (Withdrawals can be made only if the balance exceeds the withdrawal)
Opened withdraw(amount) )[amount >= balance] decreaseBalance
Overdrawn (Withdrawals exceeding the balance result in the account changing to Overdrawn)
Overdrawn deposit(amount) [amount < balance]/increaseBalance
Overdrawn (Account remains in the Overdrawn state while the amount deposited is less than the balance)
Overdrawn
deposit(amount) [amount > balance]/increaseBalance
Opened (Account changes to opened when a positive balance is achieved)
Opened close/refund Closed (request is to close account)
Closed delete Final (account is deleted)
stm CheckingAccount Draft State Diagram
Initial
New
Opened
Ov erdraw n
closed
Final
withdraw(amount) [amount>balance] /decreaseBalance
deposit(amount) /increaseBalance
deposit(amount) [amount>=balance] /increaseBalance
close /refund
create()
withdraw(amount) [amount <= blanace] /decreaseBalance
deposit(amount) [amount >= 1] /increaseBalance
delete()
State diagrams are created for classes with important or complex behavior Follow steps for creating a state diagram including: selecting classes, identifying states, identifying transitions that will cause object to advance to the next state, start building the state diagram while checking the order, look for independent concurrent paths, identify additional transitions, add details to include message events, guard condition, or action expressions, review and test.
- ENTD321 Object Oriented Programming and UML
- Example States of Classes
- CheckingAccount Class Draft Diagram
- Step 1 for Creating State Diagrams�
- Steps for Creating State Diagrams cont’d
- CheckingAccount State Analysis
- Draft CheckingAccount State Diagram
- Summary