Skip to content

Commit

Permalink
Merge pull request #74 from cxyterence/update-dg
Browse files Browse the repository at this point in the history
Update DeveloperGuide.md with implementation of ShowCommand
  • Loading branch information
guowei42 authored Oct 19, 2022
2 parents d99a4d0 + 1dad85e commit af920bb
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 0 deletions.
42 changes: 42 additions & 0 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,48 @@ _{more aspects and alternatives to be added}_

_{Explain here how the data archiving feature will be implemented}_

### Display Details of Contacts in Secondary Panel

#### Implementation

This feature is facilitated by `ShowCommand`, which extends `Command` with an index, stored internally as `index`.
It overwrites the following operations:
* `ShowCommand#execute()` — Executes the command, displaying the details of the contact at the specified index.
* `ShowCommand#equals(Object o)` — Checks if two objects are equal.

Given below is an example usage scenario and how the displaying mechanism behaves at each step.

Step 1. The user launches the application. The `AddressBook` will initially display all Persons with their `Positions`.

![ShowDiagram1](images/ShowDiagram1.png)

Step 2. The user executes `show 1` command to display the details of the first contact shown. The `show` keyowrd causes
`AddressBookParser#parseCommand()` to call `ShowCommandParser#parse()`. This returns a `ShowCommand` containing the
`index 1`.

![ShowDiagram2](images/ShowDiagram2.png)

Step 3. `Model` retrieves the `Person` object located at `index 1`. This returns a `CommandResult` containing the `Person`
object.

![ShowDiagram3](images/ShowDiagram3.png)

Step 4. `MainWindow` from `UI` component will process the `CommandResult` and display the details found inside the
included `Person` object.

The following show diagram shows how the show operation works:

![ShowSequenceDiagram](images/ShowSequenceDiagram.png)

#### Design Considerations
* **Alternative 1 (current choice):** Passing `Person` object to `MainWindow`
* Pros: Reduced coupling throughout the program
* Cons: Changing of many method signatures, unintuitive to implement at first.

* **Alternative 2:** Passing `index` to `MainWindow` to retrieve details from `Model`
* Pros: More intuitive to implement in the sense that only `MainWindow` would be primarily modified.
* Cons: Increased coupling, violation of Law of Demeter.

### Multiple Teacher’s Address Books (TABs)
**Feature Summary**
- Users are able to create multiple TABs (currently limited to 5).
Expand Down
19 changes: 19 additions & 0 deletions docs/diagrams/ShowDiagram1.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@startuml
'https://plantuml.com/object-diagram

object "<u> Walter:Person" as Walter {
position = "Professor"
phone = "91234567"
}

object "<u> Jesse:Person" as Jesse {
position = "Student"
phone = "98765432"
}

map "<u> :AddressBook" as AddressBook {
<u>:Person1 *-> Walter
<u>:Person2 *--> Jesse
}

@enduml
17 changes: 17 additions & 0 deletions docs/diagrams/ShowDiagram2.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@startuml
'https://plantuml.com/class-diagram
class ShowCommand
class Index {}

ShowCommand *-- Index

class ShowCommand {
-COMMAND_WORD
-index
equals()
execute()
}
class Index {
-zeroBasedIndex = 1
}
@enduml
20 changes: 20 additions & 0 deletions docs/diagrams/ShowDiagram3.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@startuml
'https://plantuml.com/object-diagram

object "<u> Walter:Person" as Walter {
position = "Professor"
phone = "91234567"
}

object "<u> Jesse:Person" as Jesse {
position = "Student"
phone = "98765432"
}

object "<u> :List<Person>" as lastShownList
lastShownList --> Walter
lastShownList --> Jesse

object "<u> :CommandResult" as CommandResult
CommandResult --> Walter
@enduml
58 changes: 58 additions & 0 deletions docs/diagrams/ShowSequenceDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
@startuml
!include style.puml

box Logic LOGIC_COLOR_T1
participant ":LogicManager" as LogicManager LOGIC_COLOR
participant ":AddressBookParser" as AddressBookParser LOGIC_COLOR
participant "s:ShowCommand" as ShowCommand LOGIC_COLOR
end box

box Model MODEL_COLOR_T1
participant ":Model" as Model MODEL_COLOR
participant ":List<Person>" as ListPerson MODEL_COLOR
participant "personToShow:Person" as personToShow MODEL_COLOR
end box
[-> LogicManager : execute(show)
activate LogicManager

LogicManager -> AddressBookParser : parseCommand(show)
activate AddressBookParser

create ShowCommand
AddressBookParser -> ShowCommand
activate ShowCommand

ShowCommand --> AddressBookParser
deactivate ShowCommand

AddressBookParser --> LogicManager : s
deactivate AddressBookParser

LogicManager -> ShowCommand : execute()
activate ShowCommand

ShowCommand -> Model : getFilteredPersonList()
activate Model

Model -> ListPerson
activate ListPerson

ListPerson -> personToShow : get(index.getZeroBased())
activate personToShow

personToShow --> ListPerson
deactivate personToShow

ListPerson --> Model
deactivate ListPerson

Model --> ShowCommand : personToShow
deactivate Model

ShowCommand --> LogicManager
deactivate ShowCommand

[<-- LogicManager
deactivate LogicManager

@enduml
Binary file added docs/images/ShowDiagram1.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/ShowDiagram2.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/ShowDiagram3.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/ShowSequenceDiagram.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 af920bb

Please sign in to comment.