Skip to content

Commit

Permalink
Developer Guide: Update Delete Command and its diagrams
Browse files Browse the repository at this point in the history
  • Loading branch information
ziqing26 committed Oct 18, 2021
1 parent e8d6447 commit 6019c59
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 1 deletion.
33 changes: 32 additions & 1 deletion docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ How the `Logic` component works:

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)
![Interactions Inside the Logic Component for the `delete 1` Command](images/DeleteSequenceDiagram1.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>
Expand Down Expand Up @@ -187,6 +187,37 @@ Given below is an example usage scenario:
Both methods can achieve the intended effect of implementing the recurring visits. However, we chose to go with an occurrence counter and frequency attribute because it requires less resources.
We were concerned that the recurring visits could have many occurrences and at a high frequency, and this could lead to extra overhead in storing and accessing these arrays.

### Delete command

#### Implementation details

Delete command is sued to delete an existing person or the next visit of a person in SeniorLove. It makes use of polymorphism and is similar to the other commands in SerniorLove:

* `DeleteCommand` extends `Command`
* `DeleteCommandParser` implements `Parser<DeleteCommand>`

The following activity diagram illustrates the activity flow of the delete command:
![DeleteCommandActivityDiagram](images/DeleteCommandActivityDiagram.png)

The following sequence diagram illustrate how the components interact with each other:
![DeleteSequenceDiagram2](images/DeleteSequenceDiagram2.png)

Given below is an example usage scenario:
1. User inputs the delete command, specifying the visit flag and the index of the elderly to be removed visit from. (If user wants to remove the entry of the elderly entirely instead of only removing the visit, she/he only needs to specify the index without the visit flag.)
2. After successfully parsing the user input, the `DeleteCommand#execute(Model model)` method is called.
3. The person which the user wants to delete visit from will be replaced by a new entry of a copy of person without the existing next visit.
4Upon successfully deleting the visit from the corresponding elderly, a `CommandResult` object is instantiated and returned to `LogicManager`.

#### Design choices

- Overloading `delete` to remove visit:

Deleting person and deleting visits are overlapping functionalities dealing with removing information. It is possible to overload the `delete` command to achieve both functionalities without creating new command.

- Replace the exiting person with a new instance (if deleting a visit):

We want to keep the data safe by ensuring immutability of Person objects. Therefore, we create an instance of Person with removed visit to replace the previous Person object.


### \[Proposed\] Undo/redo feature

Expand Down
26 changes: 26 additions & 0 deletions docs/diagrams/DeleteCommandActivityDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@startuml
start
:User inputs delete command;
:Logic executes delete command;
:DeleteCommandParser parses the command;

if () then ([Delete index is with in the valid range])
if() then ([Visit flag is present])
if() then ([Person at specified index has a next visit])
:deleteVisit;
else ([else])
:Throw CommandException;
endif

else ([else])

:deletePerson;
endif

else ([else])
:Throw ParseException;

endif
stop

@enduml
File renamed without changes.
105 changes: 105 additions & 0 deletions docs/diagrams/DeleteSequenceDiagram2.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
@startuml
!include style.puml

box Logic LOGIC_COLOR_T1
participant ":LogicManager" as LogicManager LOGIC_COLOR
participant ":AddressBookParser" as AddressBookParser LOGIC_COLOR
participant ":DeleteCommandParser" as DeleteCommandParser LOGIC_COLOR
participant "d:DeleteCommand" as DeleteCommand LOGIC_COLOR
participant ":CommandResult" as CommandResult LOGIC_COLOR
end box

box Model MODEL_COLOR_T1
participant ":Model" as Model MODEL_COLOR
participant ":Person" as Person MODEL_COLOR
end box

[-> LogicManager : execute("delete v/1")
activate LogicManager

LogicManager -> AddressBookParser : parseCommand("delete v/1")
activate AddressBookParser

create DeleteCommandParser
AddressBookParser -> DeleteCommandParser
activate DeleteCommandParser

DeleteCommandParser --> AddressBookParser
deactivate DeleteCommandParser

AddressBookParser -> DeleteCommandParser : parse(" v/1")
activate DeleteCommandParser

create DeleteCommand
DeleteCommandParser -> DeleteCommand
activate DeleteCommand

DeleteCommand --> DeleteCommandParser : 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

AddressBookParser --> LogicManager : d
deactivate AddressBookParser

alt no visit flag "v/" is present
LogicManager -> DeleteCommand : execute()
activate DeleteCommand

DeleteCommand -> DeleteCommand : deletePerson(1)
activate DeleteCommand

DeleteCommand -> Model : deletePerson(1)
activate Model

Model --> DeleteCommand
deactivate Model

create CommandResult
DeleteCommand -> CommandResult
activate CommandResult

CommandResult --> DeleteCommand
deactivate CommandResult

DeleteCommand --> LogicManager : result
deactivate DeleteCommand

else visit flag "v/" is present
LogicManager -> DeleteCommand : execute()
activate DeleteCommand

DeleteCommand -> DeleteCommand : deleteVisit(1)
activate DeleteCommand

create Person
DeleteCommand -> Person
activate Person

Person --> DeleteCommand: editedPerson
deactivate Person

DeleteCommand -> Model: setPerson(1, editedPerson)
activate Model

Model --> DeleteCommand
deactivate Model

create CommandResult
DeleteCommand -> CommandResult
activate CommandResult

CommandResult --> DeleteCommand
deactivate CommandResult

DeleteCommand --> LogicManager : result
deactivate DeleteCommand

end
[<--LogicManager
deactivate LogicManager
@enduml
Binary file added docs/images/DeleteCommandActivityDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added docs/images/DeleteSequenceDiagram2.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 6019c59

Please sign in to comment.