diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md index 08ade28af52..60f643f6cf6 100644 --- a/docs/DeveloperGuide.md +++ b/docs/DeveloperGuide.md @@ -94,26 +94,19 @@ The sequence diagram below illustrates the interactions within the `Logic` compo - - -**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. - - 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).
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: - - - 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) diff --git a/docs/diagrams/DeleteSequenceDiagram.puml b/docs/diagrams/DeleteSequenceDiagram.puml index 77d4485d746..b57e3452d5c 100644 --- a/docs/diagrams/DeleteSequenceDiagram.puml +++ b/docs/diagrams/DeleteSequenceDiagram.puml @@ -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 "<>\nCommandType" as CommandTypeClass LOGIC_COLOR +participant "t:CommandType" as CommandType LOGIC_COLOR +participant "<>\nDeleteCommand" as DeleteCommandClass LOGIC_COLOR participant "d:DeleteCommand" as DeleteCommand LOGIC_COLOR end box @@ -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 @@ -54,7 +66,7 @@ activate Model Model --> DeleteCommand deactivate Model -DeleteCommand --> LogicManager : r +DeleteCommand --> LogicManager : result deactivate DeleteCommand [<--LogicManager diff --git a/docs/diagrams/LogicClassDiagram.puml b/docs/diagrams/LogicClassDiagram.puml index aa1b9744f5d..3c265d2e065 100644 --- a/docs/diagrams/LogicClassDiagram.puml +++ b/docs/diagrams/LogicClassDiagram.puml @@ -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 "<>\nLogic" as Logic Class LogicManager + +Class ArgumentMultimap +Class ArgumentTokenizer +Class ParserUtil } package Model { @@ -27,17 +32,23 @@ Class HiddenOutside #FFFFFF HiddenOutside ..> Logic LogicManager .left.|> Logic -LogicManager -->"1" ParserClasses -ParserClasses ..> XYZCommand : <> +LogicManager -->"1" AddressBookParser + +AddressBookParser ..> CommandType : uses > + +CommandType .right.> XYZCommand : creates > XYZCommand -up-|> Command -LogicManager ..> Command : <> +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