Skip to content

Commit

Permalink
DG: Tweak the 'Logic component' section
Browse files Browse the repository at this point in the history
Main changes:
* Break the class diagram into two by extracting out the classes related
  to parsing.
* Tweak explanations to match.
  • Loading branch information
damithc committed Jul 31, 2021
1 parent ff572e9 commit b8eccd5
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 39 deletions.
27 changes: 16 additions & 11 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,27 +86,32 @@ The `UI` component,

### Logic component

![Structure of the Logic Component](images/LogicClassDiagram.png)
**API** : [`Logic.java`](https://github.com/se-edu/addressbook-level3/tree/master/src/main/java/seedu/address/logic/Logic.java)

**API** :
[`Logic.java`](https://github.com/se-edu/addressbook-level3/tree/master/src/main/java/seedu/address/logic/Logic.java)
Here's a (partial) class diagram of the `Logic` component:

1. `Logic` uses the `AddressBookParser` class to parse the user command.
1. This results in a `Command` object which is executed by the `LogicManager`.
1. The command execution can affect the `Model` (e.g. adding a person).
1. The result of the command execution is encapsulated as a `CommandResult` object which is passed back to the `Ui`.
1. In addition, the `CommandResult` object can also instruct the `Ui` to perform certain actions, such as displaying help to the user.
<img src="images/LogicClassDiagram.png" width="550"/>

Given below is the Sequence Diagram for interactions within the `Logic` component for the `execute("delete 1")` API call.
How the `Logic` component works:
1. When `Logic` is called upon to execute a command, it uses the `AddressBookParser` class to parse the user command.
1. This results in a `Command` object (more precisely, an object of one of its subclasses e.g., `AddCommand`) which is executed by the `LogicManager`.
1. The command can communicate with the `Model` when it is executed (e.g. to add a person).
1. The result of the command execution is encapsulated as a `CommandResult` object which is returned back from `Logic`.

The Sequence Diagram below illustrates the interactions within the `Logic` component for the `execute("delete 1")` API call.

![Interactions Inside the Logic Component for the `delete 1` Command](images/DeleteSequenceDiagram.png)

<div markdown="span" class="alert alert-info">:information_source: **Note:** The lifeline for `DeleteCommandParser` should end at the destroy marker (X) but due to a limitation of PlantUML, the lifeline reaches the end of diagram.
</div>

### Model component
Here are the other classes in `Logic` (omitted from the class diagram above) that are used for parsing a user command:

<img src="images/ParserClasses.png" width="600"/>

![Structure of the Model Component](images/ModelClassDiagram.png)
How the parsing works:
* When called upon to parse a user command, the `AddressBookParser` class creates an `XYZCommandParser` (`XYZ` is a placeholder for the specific command name e.g., `AddCommandParser`) which uses the other classes shown above to parse the user command and create a `XYZCommand` object (e.g., `AddCommand`) which the `AddressBookParser` returns back as a `Command` object.
* All `XYZCommandParser` classes (e.g., `AddCommandParser`, `DeleteCommandParser`, ...) inherit from the `Parser` interface so that they can be treated similarly where possible e.g, during testing.

**API** : [`Model.java`](https://github.com/se-edu/addressbook-level3/tree/master/src/main/java/seedu/address/model/Model.java)

Expand Down
33 changes: 5 additions & 28 deletions docs/diagrams/LogicClassDiagram.puml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,11 @@ skinparam classBackgroundColor LOGIC_COLOR

package Logic {

package Parser {
Interface Parser <<Interface>>
Class AddressBookParser
Class XYZCommandParser
Class CliSyntax
Class ParserUtil
Class ArgumentMultimap
Class ArgumentTokenizer
Class Prefix
}

package Command {
Class XYZCommand
Class CommandResult
Class "{abstract}\nCommand" as Command
}


Interface Logic <<Interface>>
Class LogicManager
Expand All @@ -32,26 +21,15 @@ Class HiddenModel #FFFFFF
}

package Storage{
Class HiddenModel #FFFFFF
}

Class HiddenOutside #FFFFFF
HiddenOutside ..> Logic

LogicManager .up.|> Logic
LogicManager -->"1" AddressBookParser
AddressBookParser .left.> XYZCommandParser: creates >
LogicManager .right.|> Logic
LogicManager -right->"1" AddressBookParser
AddressBookParser ..> XYZCommand : creates >

XYZCommandParser ..> XYZCommand : creates >
XYZCommandParser .left.|> Parser
XYZCommandParser ..> ArgumentMultimap
XYZCommandParser ..> ArgumentTokenizer
ArgumentTokenizer .left.> ArgumentMultimap
XYZCommandParser ..> CliSyntax
CliSyntax ..> Prefix
XYZCommandParser ..> ParserUtil
ParserUtil .down.> Prefix
ArgumentTokenizer .down.> Prefix
XYZCommand -up-|> Command
LogicManager .left.> Command : executes >

Expand All @@ -64,6 +42,5 @@ note right of XYZCommand: XYZCommand = AddCommand, \nFindCommand, etc

Logic ..> CommandResult
LogicManager .down.> CommandResult
Command .up.> CommandResult
CommandResult -[hidden]-> Parser
Command .up.> CommandResult : produces >
@enduml
38 changes: 38 additions & 0 deletions docs/diagrams/ParserClasses.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@startuml
!include style.puml
skinparam arrowThickness 1.1
skinparam arrowColor LOGIC_COLOR_T4
skinparam classBackgroundColor LOGIC_COLOR

Class "{abstract}\nCommand" as Command
Class XYZCommand

package "Parser classes"{
Interface Parser <<Interface>>
Class AddressBookParser
Class XYZCommandParser
Class CliSyntax
Class ParserUtil
Class ArgumentMultimap
Class ArgumentTokenizer
Class Prefix
}

Class HiddenOutside #FFFFFF
HiddenOutside ..> AddressBookParser

AddressBookParser .down.> XYZCommandParser: creates >

XYZCommandParser ..> XYZCommand : creates >
AddressBookParser ..> Command : returns >
XYZCommandParser .up.|> Parser
XYZCommandParser ..> ArgumentMultimap
XYZCommandParser ..> ArgumentTokenizer
ArgumentTokenizer .left.> ArgumentMultimap
XYZCommandParser ..> CliSyntax
CliSyntax ..> Prefix
XYZCommandParser ..> ParserUtil
ParserUtil .down.> Prefix
ArgumentTokenizer .down.> Prefix
XYZCommand -up-|> Command
@enduml
Binary file modified docs/images/LogicClassDiagram.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/ParserClasses.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b8eccd5

Please sign in to comment.