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 for Logic component #100

Merged
merged 8 commits into from
Mar 20, 2024
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
19 changes: 6 additions & 13 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,19 @@ The sequence diagram below illustrates the interactions within the `Logic` compo

<puml src="diagrams/DeleteSequenceDiagram.puml" alt="Interactions Inside the Logic Component for the `delete 1` Command" />

<box type="info" seamless>

**Note:** The lifeline for `DeleteCommandParser` should end at the destroy marker (X) but due to a limitation of PlantUML, the lifeline continues till the end of diagram.
</box>

How the `Logic` component works:

1. When `Logic` is called upon to execute a command, it is passed to an `AddressBookParser` object which in turn creates a parser that matches the command (e.g., `DeleteCommandParser`) and uses it to parse the command.
1. This results in a `Command` object (more precisely, an object of one of its subclasses e.g., `DeleteCommand`) which is executed by the `LogicManager`.
1. When `Logic` is called upon to execute a command, it is passed to an `AddressBookParser` object which in turn uses an enum factory `CommandType` to create the relevant enum (e.g. `CommandType.DELETE`) with the input arguments.
1. The `CommandType` enum calls the relevant command's factory method to create a command object (e.g. `DeleteCommand`).
1. The command can communicate with the `Model` when it is executed (e.g. to delete a person).<br>
Note that although this is shown as a single step in the diagram above (for simplicity), in the code it can take several interactions (between the command object and the `Model`) to achieve.
1. The result of the command execution is returned back from `Logic` as a `String`.

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

<puml src="diagrams/ParserClasses.puml" width="600"/>

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.

1. The `AddressBookParser` passes the first token to `CommandType` which dispatches the matching type of command.
2. `AddressBookParser` instantiates the command with the user input arguments.
3. The command object (e.g. `DeleteCommand`) uses `ArgumentTokenizer`, `ArgumentMultimap` and possibly `ParserUtil` to break down and interpret the user input arguments.

### Model component
**API** : [`Model.java`](https://github.com/se-edu/addressbook-level3/tree/master/src/main/java/seedu/address/model/Model.java)
Expand Down
44 changes: 28 additions & 16 deletions docs/diagrams/DeleteSequenceDiagram.puml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ skinparam ArrowFontStyle plain
box Logic LOGIC_COLOR_T1
participant ":LogicManager" as LogicManager LOGIC_COLOR
participant ":AddressBookParser" as AddressBookParser LOGIC_COLOR
participant ":DeleteCommandParser" as DeleteCommandParser LOGIC_COLOR
participant "<<class>>\nCommandType" as CommandTypeClass LOGIC_COLOR
participant "t:CommandType" as CommandType LOGIC_COLOR
participant "<<class>>\nDeleteCommand" as DeleteCommandClass LOGIC_COLOR
participant "d:DeleteCommand" as DeleteCommand LOGIC_COLOR
end box

Expand All @@ -19,32 +21,42 @@ activate LogicManager
LogicManager -> AddressBookParser : parseCommand("delete 1")
activate AddressBookParser

create DeleteCommandParser
AddressBookParser -> DeleteCommandParser
activate DeleteCommandParser
AddressBookParser -> CommandTypeClass : valueOf("DELETE")
activate CommandTypeClass

DeleteCommandParser --> AddressBookParser
deactivate DeleteCommandParser
create CommandType
CommandTypeClass -> CommandType
activate CommandType

AddressBookParser -> DeleteCommandParser : parse("1")
activate DeleteCommandParser
CommandType -> CommandTypeClass : t
deactivate CommandType

CommandTypeClass -> AddressBookParser : t
deactivate CommandTypeClass

AddressBookParser -> CommandType : createCommand()
activate CommandType

CommandType -> DeleteCommandClass : of("1")
activate DeleteCommandClass

create DeleteCommand
DeleteCommandParser -> DeleteCommand
DeleteCommandClass -> DeleteCommand
activate DeleteCommand

DeleteCommand --> DeleteCommandParser :
DeleteCommand --> DeleteCommandClass : d
deactivate DeleteCommand

DeleteCommandParser --> AddressBookParser : d
deactivate DeleteCommandParser
'Hidden arrow to position the destroy marker below the end of the activation bar.
DeleteCommandParser -[hidden]-> AddressBookParser
destroy DeleteCommandParser
DeleteCommandClass --> CommandType : d
deactivate DeleteCommandClass

CommandType --> AddressBookParser : d
deactivate CommandType

AddressBookParser --> LogicManager : d
deactivate AddressBookParser


LogicManager -> DeleteCommand : execute(m)
activate DeleteCommand

Expand All @@ -54,7 +66,7 @@ activate Model
Model --> DeleteCommand
deactivate Model

DeleteCommand --> LogicManager : r
DeleteCommand --> LogicManager : result
deactivate DeleteCommand

[<--LogicManager
Expand Down
27 changes: 19 additions & 8 deletions docs/diagrams/LogicClassDiagram.puml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ skinparam classBackgroundColor LOGIC_COLOR

package Logic as LogicPackage {

package "Parser Classes" as ParserClasses {
}
Class AddressBookParser

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


Class "<<interface>>\nLogic" as Logic
Class LogicManager

Class ArgumentMultimap
Class ArgumentTokenizer
Class ParserUtil
}

package Model {
Expand All @@ -27,17 +32,23 @@ Class HiddenOutside #FFFFFF
HiddenOutside ..> Logic

LogicManager .left.|> Logic
LogicManager -->"1" ParserClasses
ParserClasses ..> XYZCommand : <<create>>
LogicManager -->"1" AddressBookParser

AddressBookParser ..> CommandType : uses >

CommandType .right.> XYZCommand : creates >

XYZCommand -up-|> Command
LogicManager ..> Command : <<call>>
LogicManager ..> Command : executes >

LogicManager --> Model
LogicManager --> Storage
Storage --[hidden] Model
Command .[hidden]up.> Storage
LogicManager -right-> Storage

Command .right.> Model
note right of XYZCommand: XYZCommand = AddCommand, \nFindCommand, etc

XYZCommand ..> ArgumentMultimap
XYZCommand ..> ArgumentTokenizer
XYZCommand ..> ParserUtil
ArgumentTokenizer .left.> ArgumentMultimap
@enduml