Problem definition
This section represents the initial requirements and expectations provided by the interviewer.
Example:
Design a vending machine for snacks.
Requirement collection (tree of numbered requirements)
It contains a numbered list of requirements (R1…RNN). It would be more effective to classify the requirements by objects and actions, and separately designate requirements for performance.
Example:
R1. Different products can be placed at various positions in the machine.
R2. The machine can be in one of these three states: - no money inserted, money inserted or dispense.
…
RNN. While payment is insufficient, the machine displays a message indicating the necessary amount.
Case Diagram:
System
Example:
A vending machine is our system.
The system could be, for example, the Amazon Locker System, a vending Machine, or an elevator System.
Actors:
- Primary
- Secondary
Example:
Primary actors are the Customer and the Operator.
Secondary actor is the System.
Use Cases:
What do actors do?
Example:
Customer selects, takes products, inserts money, takes change.
Operator selects, insert, remove products, insert, remove money.
System validates money, return change, search, dispense products.
Relationships:
Association, Generalization, Include, Extend.
Example:
Generalization: the Operator has the same powers as the Customer, but additionally can insert products and dispense money. Therefore, the Operator has a generalization relationship with the Customer actor.
Include:
"Select product" use case includes "Search product"
"Dispense product" use case include "Validate money" and "Return change".
Associations:
Customer | Operator | System |
Select product | Add product | Search product |
Take product | Remove product | Dispense product |
Insert money | Select product | Validate money |
Take change | Insert money | Return change |
Dispense money |
Diagram
Class Diagram
Bottom-Top approach: Small components -> Middle components -> Big Components
The solution architecture should be divided into blocks, ranging from the smallest to the medium and large blocks.
Example:
Classes: Product -> Rack -> Inventory -> Vending machine.
Interfaces: State (represents the current state of the vending machine).
Enumerations: Product type
Relationships between classes:
Relationships can be association (including inheritance), composition or aggregation.
Especially, here we can denote the association of the objects (one-way, two-way, n-ary).
Design patterns
In this section we list possible design patterns that could be applied to the solution.
Example:
The vending machine can be considered as a state machine, and the "State machine" pattern could be applied to it.
We also assume that there is a single instance of the vending machine, hence the singleton pattern takes place.
Diagram
Sequence Diagram
Identify the use case
The sequence diagram outlines a selected use case, detailing the order of actions.
Example:
The customer takes a product from the vending machine.
Actors and Objects
We should identify the list of actors and objects that will be involved in the use case.
Example:
The customer, vending machine, product, inventory, bill validator.
Steps
Before creating the diagram, it could be useful to compose a list of actions used in the case.
Example:
1. Customer selects a product.
2. System checks the number of product.
3. System requests amount or prints that the product number is incorrect.
4. The customer puts money to the bill validator.
5. When inserted amount is enough, the system dispenses the product.
Diagram
Activity diagram
This kind of diagram is used to illustrate the dynamic aspects performed by a system, similar to a flowchart.
Chosen activity
Each activity diagram represents some chosen workflow in a tree structure.
Example:
The product purchase activity using a vending machine.
States: initial, intermediate, final
The activity diagram depicts the progression of an activity through different states, starting from the initial state, passing through a series of intermediate states, and ending with the final state.
Example:
During the product purchase, the vending machine transitions through a series of states: money inserted (false to true) -> product available (false to true) -> money validated (false to true) -> product dispensed (false to true).
Actions
Actions change the state of the system.
Example:
Select product, insert money, validate money, dispense change, dispense product.
Diagram
Code
The proposed solution should be implemented in your preferred programming language.