Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DG: parser class and help command #165

Merged
merged 8 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
## Design

### Parser
API: [Parser.java]({repoURL}src/main/java/seedu/cafectrl/parser/Parser.java)

![Parser Parsing User Input Sequence Diagram](images/sequence/Parser.png)
![Parser Class Diagram](images/class/Parser.png)

*Figure 1: Parser Parsing User Input Sequence Diagram*
*Figure 1: Parser Class Diagram*

API: [Parser.java]({repoURL}src/main/java/seedu/cafectrl/parser/Parser.java)
Note that `CafeCtrl` only have access to the interface `ParserUtil` although the run-time type object is `Parser`. With this, we are able to decrease coupling between `CafeCtrl` and `Parser`, allowing for easier maintainance. This also ensures the testability as we could provide mock or stub dependencies during testing, we could isolate the behavior of the class and focus on unit testing without external dependencies.

![Parser Parsing User Input Sequence Diagram](images/sequence/Parser.png)

*Figure 2: Parser Parsing User Input Sequence Diagram*

When user input a string to `Main`, it passes the full user input to `Parser` via `parseCommand`. In `parseCommand`, it finds the matching keyword for different command from the user input, then it calls the respective `prepareCommand` method within `Parser`. `prepareCommand` then generates the corresponding command class and return it to `parseCommand`, which returns the `Command` back to `Main` for execution.

Expand Down Expand Up @@ -101,7 +106,17 @@ This sequence of actions orchestrates the flow of information and operations bet

API: [EditPriceCommand.java]({repoURL}src/main/java/seedu/cafectrl/command/EditPriceCommand.java)

When the `execute()` method of `EditPriceCommand` is invoked in `Main`, it subsequently calls the `setPrice()` method on the `Dish` object to modify the price of the specific dish. Following this, the `showEditPriceMessages()` method in the Ui component is triggered to display a message related to the successful execution of the price modification process. This sequence of actions orchestrates the flow of information and operations between the `Main`, `EditPriceCommand`, `Dish`, and `Ui` components, ensuring the seamless handling of the price editing functionality within the application.
When the `execute()` method of `EditPriceCommand` is invoked in `Main`, it subsequently calls the `setPrice()` method on the `Dish` object to modify the price of the specific dish. Following this, the `showEditPriceMessages()` method in the `Ui` component is triggered to retrieve and display a message from `Messages` related to the successful execution of the price modification process. This sequence of actions orchestrates the flow of information and operations between the `Main`, `EditPriceCommand`, `Dish`, and `Ui` components, ensuring the seamless handling of the price editing functionality within the application.

### Help

![Help Execution](images/sequence/HelpCommand_execute.png)

*figure 4: Execution of help command*

API: [HelpCommand.java]({repoURL}src/main/java/seedu/cafectrl/command/HelpCommand.java)

When the `execute()` method of `HelpCommand` is invoked in `Main`, it subsequently calls the `showHelp()` method in `Ui`. In `showHelp()`, messages related to command usage will be retrieved and be printed out using by self-invoking `showToUserWithSpaceInBetweenLines(messages: String...)`.

## Product scope
### Target user profile
Expand Down
34 changes: 34 additions & 0 deletions docs/diagrams/class/Parser.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@startuml
interface ParserUtil {
+parseCommand(): Command
}

class Parser {
-{static}INPUT_REGEX: String
+parseCommand(): Command
-prepareXYZCommand(): Command
-parsePriceToFloat(priceText: String): float
-parseIngredient(ingredientsListString: String): ArrayList<Ingredient>
}

abstract class Command {
+execute(): void
}

class XYZCommand {
+execute(): void
}

class Ui {
+showToUser(textToShow: String): void
}

CafeCtrl ..> ParserUtil: use
XYZCommand --|> Command
CafeCtrl ..> Command: execute
ParserUtil <|.. Parser
Parser ..> XYZCommand: create
XYZCommand *-- data: use
note left: Classes in data package: Dish, Ingredient, \nCurrentData, Menu, Order, Pantry and Sales
Command *-- Ui: use
@enduml
19 changes: 16 additions & 3 deletions docs/diagrams/sequence/EditPriceCommand_execute.puml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,22 @@ autonumber

Main -> EditPriceCommand: execute()
activate EditPriceCommand
EditPriceCommand -> Dish: setPrice(price: float)
EditPriceCommand -> Menu:getDishFromId(menuID: int)
activate Menu
Menu --> EditPriceCommand: (dish: Dish)
deactivate Menu
EditPriceCommand -> Dish: setPrice(newPrice: float)
activate Dish
EditPriceCommand -> Ui: showEditPriceMessages()
EditPriceCommand -> Ui: showEditPriceMessages(dishString: String)
deactivate Dish
activate Ui
activate Messages
activate Ui
Ui -> Messages: + PRICE_MODIFIED_MESSAGE: String
Messages --> Ui: "Price modified for the following dish: "
deactivate Messages
Ui -> Ui: showToUser("Price modified for the following dish: ", dishString: String)
deactivate Ui
deactivate EditPriceCommand
deactivate Dish
@enduml
@enduml
14 changes: 14 additions & 0 deletions docs/diagrams/sequence/HelpCommand_execute.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@startuml
'https://plantuml.com/sequence-diagram

autonumber

Main -> HelpCommand: execute()
activate HelpCommand
HelpCommand -> Ui: showHelp()
activate Ui
Ui -> Ui: showToUserWithSpaceBetweenLines(messages: String...)
activate Ui
deactivate Ui

@enduml
21 changes: 10 additions & 11 deletions docs/diagrams/sequence/Parser.puml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ activate Main
Main -> Parser: parseCommand(fullUserInput: String)
activate Parser

alt COMMAND_WORD
Parser -> Parser: prepareCommand(requiredArguments)
alt XYZCOMMAND_WORD
Parser -> Parser: prepareXYZCommand(requiredArguments)
activate Parser
Parser -> Command: Command()
activate Command
Command --> Parser: command
deactivate Command
Parser -> XYZCommand: XYZCommand(requiredArguments)
activate XYZCommand
XYZCommand --> Parser: XYZCommand
deactivate XYZCommand
deactivate Parser
end alt

Parser --> Main: XYZCommand
deactivate Parser

Parser --> Main: command
Main -> Command: execute()
activate Command
@enduml
Main -> XYZCommand: execute()
activate XYZCommand
@enduml
Binary file added docs/images/class/Parser.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/sequence/EditPriceCommand_execute.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/sequence/HelpCommand_execute.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/sequence/Parser.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.