diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md index e53fe846187..401441cbad5 100644 --- a/docs/DeveloperGuide.md +++ b/docs/DeveloperGuide.md @@ -212,6 +212,46 @@ The following activity diagram summarizes what happens when a tutor executes a f * Pros: Useful for the entire application, and would use less memory (e.g. storing the first 10 commands). * Cons: Harder to implement. +### Payment Command + +#### Implementation + +The payment command in the Address book application is implemented using the PaymentPredicate, which extends the Predicate functional interface. +This predicate is used to set a condition for filtering students based on whether they have paid or not paid. + +The application allows updating the payment predicate using the Model#updateFilteredPersonList(predicate) method. + +The Payment class is added as an additional data field in the Person class. +* When unspecified: + * `Payment()` equals to `Payment("-")` (i.e. "-" will be shown when there is no payment for the student.) + +Given below is an example usage scenario and what the predicate is at each step. + +Step 1. The user launches the application for the first time. The student's contacts in the form of FilteredList will be shown, where the predicate states that the payment condition is true for all. + +Step 2. The user executes `Payment pa/paid` command to get all students in the `FilteredList` who has an "Paid". The `payment` command creates `PaymentFilterPredicate`, and calls `Model#updateFilteredPersonList(predicate)`, updating the list to show students that has "Paid". + +![PaymentFilterState](images/FilterState2-PaymentFilteredList.png) + +Calling `list` command will revert the predicate back to `Model.PREDICATE_SHOW_ALL_PERSONS`. + +
+The following sequence diagram shows how a Payment filter operation goes through the `Logic` component: + +![PaymentSequenceDiagram-Logic](images/PaymentSequenceDiagram-Logic.png) + +
:information_source: **Note:** Similarly to filter command, the lifeline for `PaymentCommand` should end at the destroy marker (X) but due to a limitation of PlantUML, the lifeline reaches the end of diagram. + +
+ +Similarly, how a filter operation goes through the `Model` component is shown below: + +![FilterSequenceDiagram-Model](images/FilterSequenceDiagram-Model.png) + +The following activity diagram summarizes what happens when a tutor executes a filter command. + +![FilterActivityDiagram](images/PaymentActivityDiagram.png) + ### View Command #### Implementation diff --git a/docs/diagrams/FilterState2.puml b/docs/diagrams/FilterState2.puml new file mode 100644 index 00000000000..ed638134a5e --- /dev/null +++ b/docs/diagrams/FilterState2.puml @@ -0,0 +1,17 @@ +@startuml +!include style.puml +skinparam ClassFontColor #000000 +skinparam ClassBorderColor #000000 +skinparam ClassBackgroundColor #FFFFAA + +title FilteredList + +package Predicates { + class State1 as "Model.PREDICATE_SHOW_ALL_PERSONS" + class State2 as ":GradeSubjectFilterPredicate" +} +State1 -[hidden]right-> State2 + +class Pointer as "Current State" #FFFFFF +Pointer -up-> State2 +@end diff --git a/docs/diagrams/PaymentActivityDiagram.puml b/docs/diagrams/PaymentActivityDiagram.puml new file mode 100644 index 00000000000..e5dd5461703 --- /dev/null +++ b/docs/diagrams/PaymentActivityDiagram.puml @@ -0,0 +1,14 @@ +@startuml +skin rose +skinparam ActivityFontSize 15 +skinparam ArrowFontSize 12 +start +:User executes filter command; + +'Since the beta syntax does not support placing the condition outside the +'diamond we place it as the true branch instead. + +:System updates filter predicate; +:Returns filtered student list; +stop +@enduml diff --git a/docs/diagrams/PaymentSequenceDiagram-Logic.puml b/docs/diagrams/PaymentSequenceDiagram-Logic.puml new file mode 100644 index 00000000000..7c1f2d71247 --- /dev/null +++ b/docs/diagrams/PaymentSequenceDiagram-Logic.puml @@ -0,0 +1,55 @@ +@startuml +!include style.puml +skinparam ArrowFontStyle plain + +box Logic LOGIC_COLOR_T1 +participant ":LogicManager" as LogicManager LOGIC_COLOR +participant ":AddressBookParser" as AddressBookParser LOGIC_COLOR +participant ":PaymentCommand" as FilterCommand LOGIC_COLOR +participant ":PaymentFilterPredicate" as GradeSubjectFilterPredicate LOGIC_COLOR +end box + +box Model MODEL_COLOR_T1 +participant ":Model" as Model MODEL_COLOR +end box +[-> LogicManager : execute(payment pa/...) +activate LogicManager + +LogicManager -> AddressBookParser : parseCommand() +activate AddressBookParser + +create GradeSubjectFilterPredicate +AddressBookParser -> GradeSubjectFilterPredicate +activate GradeSubjectFilterPredicate + +GradeSubjectFilterPredicate --> AddressBookParser +deactivate GradeSubjectFilterPredicate + +create FilterCommand +AddressBookParser -> FilterCommand +activate FilterCommand + +FilterCommand --> AddressBookParser +deactivate FilterCommand + +AddressBookParser --> LogicManager +deactivate AddressBookParser + +LogicManager -> FilterCommand : execute() +activate FilterCommand + +FilterCommand -> Model : updateFilteredPersonList(predicate) +activate Model + +Model --> FilterCommand +deactivate Model + +FilterCommand --> LogicManager : commandResult +deactivate FilterCommand +FilterCommand -[hidden]-> LogicManager : commandResult +destroy FilterCommand +destroy GradeSubjectFilterPredicate + +[<--LogicManager +deactivate LogicManager +@enduml