Skip to content

Commit

Permalink
Merge branch 'master' into PED_Bugs
Browse files Browse the repository at this point in the history
# Conflicts:
#	docs/UserGuide.md
  • Loading branch information
AbdulrahmanAlRammah committed Nov 12, 2024
2 parents 2fb7f5f + cdcccb4 commit e5b31c0
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 85 deletions.
92 changes: 13 additions & 79 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,98 +158,32 @@ Classes used by multiple components are in the `seedu.address.commons` package.

This section describes some noteworthy details on how certain features are implemented.

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

#### Proposed Implementation
#### Implementation

The proposed undo/redo mechanism is facilitated by `VersionedAddressBook`. It extends `AddressBook` with an undo/redo history, stored internally as an `addressBookStateList` and `currentStatePointer`. Additionally, it implements the following operations:
The seed feature seeds dummy data into SocialBook. In the event that the user clears all the contacts in SocialBook, the user can execute the seed command to seed sample data into the SocialBook and continue trying out its features.

* `VersionedAddressBook#commit()` — Saves the current address book state in its history.
* `VersionedAddressBook#undo()` — Restores the previous address book state from its history.
* `VersionedAddressBook#redo()` — Restores a previously undone address book state from its history.
The seed command works just like any other `Command` object and how a `Command` object communicates with the `Model` is explained in the [Logic component](#logic-component).

These operations are exposed in the `Model` interface as `Model#commitAddressBook()`, `Model#undoAddressBook()` and `Model#redoAddressBook()` respectively.
The seed command adds a `Person` object, in `SampleDataUtil` to the `Model`, if the `Person` object is not already inside SocialBook.

Given below is an example usage scenario and how the undo/redo mechanism behaves at each step.
The following activity diagram summarises what happens when a user executes the seed command:

Step 1. The user launches the application for the first time. The `VersionedAddressBook` will be initialized with the initial address book state, and the `currentStatePointer` pointing to that single address book state.
<puml src="diagrams/SeedActivityDiagram.puml" alt="SeedActivityDiagram" />

<puml src="diagrams/UndoRedoState0.puml" alt="UndoRedoState0" />
### View feature

Step 2. The user executes `delete 5` command to delete the 5th person in the address book. The `delete` command calls `Model#commitAddressBook()`, causing the modified state of the address book after the `delete 5` command executes to be saved in the `addressBookStateList`, and the `currentStatePointer` is shifted to the newly inserted address book state.
#### Implementation

<puml src="diagrams/UndoRedoState1.puml" alt="UndoRedoState1" />
The view feature toggles the card status of a contact in SocialBook to either show all of their information or an abridged version of it.

Step 3. The user executes `add n/David …​` to add a new person. The `add` command also calls `Model#commitAddressBook()`, causing another modified address book state to be saved into the `addressBookStateList`.
The view command works just like any other `Command` object and how a `Command` object communicates with the `Model` is explained in the [Logic component](#logic-component).

<puml src="diagrams/UndoRedoState2.puml" alt="UndoRedoState2" />
The activity diagram below shows how a view command toggles the card status of a contact:

<box type="info" seamless>

**Note:** If a command fails its execution, it will not call `Model#commitAddressBook()`, so the address book state will not be saved into the `addressBookStateList`.

</box>

Step 4. The user now decides that adding the person was a mistake, and decides to undo that action by executing the `undo` command. The `undo` command will call `Model#undoAddressBook()`, which will shift the `currentStatePointer` once to the left, pointing it to the previous address book state, and restores the address book to that state.

<puml src="diagrams/UndoRedoState3.puml" alt="UndoRedoState3" />


<box type="info" seamless>

**Note:** If the `currentStatePointer` is at index 0, pointing to the initial SocialBook state, then there are no previous SocialBook states to restore. The `undo` command uses `Model#canUndoAddressBook()` to check if this is the case. If so, it will return an error to the user rather
than attempting to perform the undo.

</box>

The following sequence diagram shows how an undo operation goes through the `Logic` component:

<puml src="diagrams/UndoSequenceDiagram-Logic.puml" alt="UndoSequenceDiagram-Logic" />

<box type="info" seamless>

**Note:** The lifeline for `UndoCommand` should end at the destroy marker (X) but due to a limitation of PlantUML, the lifeline reaches the end of diagram.

</box>

Similarly, how an undo operation goes through the `Model` component is shown below:

<puml src="diagrams/UndoSequenceDiagram-Model.puml" alt="UndoSequenceDiagram-Model" />

The `redo` command does the opposite — it calls `Model#redoAddressBook()`, which shifts the `currentStatePointer` once to the right, pointing to the previously undone state, and restores the address book to that state.

<box type="info" seamless>

**Note:** If the `currentStatePointer` is at index `addressBookStateList.size() - 1`, pointing to the latest address book state, then there are no undone SocialBook states to restore. The `redo` command uses `Model#canRedoAddressBook()` to check if this is the case. If so, it will return an error to the user rather than attempting to perform the redo.

</box>

Step 5. The user then decides to execute the command `list`. Commands that do not modify the address book, such as `list`, will usually not call `Model#commitAddressBook()`, `Model#undoAddressBook()` or `Model#redoAddressBook()`. Thus, the `addressBookStateList` remains unchanged.

<puml src="diagrams/UndoRedoState4.puml" alt="UndoRedoState4" />

Step 6. The user executes `clear`, which calls `Model#commitAddressBook()`. Since the `currentStatePointer` is not pointing at the end of the `addressBookStateList`, all address book states after the `currentStatePointer` will be purged. Reason: It no longer makes sense to redo the `add n/David …​` command. This is the behavior that most modern desktop applications follow.

<puml src="diagrams/UndoRedoState5.puml" alt="UndoRedoState5" />

The following activity diagram summarizes what happens when a user executes a new command:

<puml src="diagrams/CommitActivityDiagram.puml" width="250" />

#### Design considerations:

**Aspect: How undo & redo executes:**

* **Alternative 1 (current choice):** Saves the entire address book.
* Pros: Easy to implement.
* Cons: May have performance issues in terms of memory usage.

* **Alternative 2:** Individual command knows how to undo/redo by
itself.
* Pros: Will use less memory (e.g. for `delete`, just save the person being deleted).
* Cons: We must ensure that the implementation of each individual command are correct.
<puml src="diagrams/ViewActivityDiagram.puml" alt="ViewActivityDiagram" />

_{more aspects and alternatives to be added}_

### \[Proposed\] Visit History

Expand Down
6 changes: 3 additions & 3 deletions docs/diagrams/LogicClassDiagram.puml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ HiddenOutside ..> Logic

LogicManager .right.|> Logic
LogicManager -right->"1" ParserClasses
ParserClasses ..> XYZCommand : <<create>>
ParserClasses ..> XYZCommand : creates >

XYZCommand -up-|> Command
LogicManager .left.> Command : <<call>>
LogicManager .left.> Command : calls >

LogicManager --> Model
LogicManager --> Storage
Expand All @@ -43,5 +43,5 @@ note right of XYZCommand: XYZCommand = AddCommand, \nFindCommand, etc

Logic ..> CommandResult
LogicManager .down.> CommandResult
Command .up.> CommandResult : <<create>>
Command .up.> CommandResult : creates >
@enduml
6 changes: 3 additions & 3 deletions docs/diagrams/ParserClasses.puml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ Class Prefix
Class HiddenOutside #FFFFFF
HiddenOutside ..> AddressBookParser

AddressBookParser .down.> XYZCommandParser: <<create>>
AddressBookParser .down.> XYZCommandParser: creates >

XYZCommandParser ..> XYZCommand : <<create>>
AddressBookParser ..> Command : <<use>>
XYZCommandParser ..> XYZCommand : creates >
AddressBookParser ..> Command : uses >
XYZCommandParser .up.|> Parser
XYZCommandParser ..> ArgumentMultimap
XYZCommandParser ..> ArgumentTokenizer
Expand Down
16 changes: 16 additions & 0 deletions docs/diagrams/SeedActivityDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@startuml
'https://plantuml.com/activity-diagram-beta

start
:user executes seed command;

repeat
if () then ([model.hasPerson()])
:continue;
else ([else])
:add person to model;
endif
repeat while () is ([else]) not ([all sample persons in model])
stop

@enduml
21 changes: 21 additions & 0 deletions docs/diagrams/ViewActivityDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@startuml
'https://plantuml.com/activity-diagram-beta

start
:user executes view command;
if () then ([valid person's index])
:get person at index;
if () then ([person has full view toggled])
:Display full contact
card of person;
else ([else])
:Display abridged version
of card;
endif
else ([else])
:throw exception;
endif

stop

@enduml

0 comments on commit e5b31c0

Please sign in to comment.