Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AB3: Tracing Code] Add Model tracing code #45

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

UdhayaShan1
Copy link

@UdhayaShan1 UdhayaShan1 commented Jul 11, 2024

Issue mentioned in #16

While tutorial touches on the Logic overview, I believe it can be useful to touch on the Model interactions as well. There could be existing confusion on FilteredPersons and hence this could alleviate some doubts, especially if they wish to work with AddressBook's list of persons.

Using the same edit command,

  1. New sequence diagram to show Model lower level
setPredicate
  1. Continue with tracing similar to tutorial
  2. Break up the code into sections so they better understand the purpose of the code
setPredicate

Copy link
Contributor

@damithc damithc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@UdhayaShan1 I can see how this can provide more explanations to the reader. What I don't like is that the UML diagram seemingly show low-level details of two components. This is caused by the filtered list, which is used for data exchange, is appearing inside the Model component. Let me fiddle with this diagram a bit and see if there's a way around it.

BTW, no need to commit the generated UML diagram. MarkBind generates it automatically. Just put the .puml file where you put the .png file, and use a <puml ... tag in the code where you need to show the diagram. To give an example from the same codebase:

<puml src="images/add-remark/ParserClass.puml" 
    alt="The relationship between Parser and RemarkCommandParser"/>

Copy link
Contributor

@NeoHW NeoHW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Insightful changes! I have some comments regarding some nits and best practices which can be considered ◡̈

Comment on lines 278 to 280
1. In our previous discussions, we've primarily focused on the `Logic` component to understand the general flow of logic when executing commands.
2. Now, let's delve into how the `EditCommand#execute()` method interacts with the `Model` component.
3. Let us reproduce the full code of `EditCommand#execute()`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps could consider using generic numbers (1. for all instead of 2., 3....)
With generic numbers, we would be able to insert items into the middle of the list without modifying others in the future.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent thanks

tutorials/ab3TracingCode.md Outdated Show resolved Hide resolved
tutorials/ab3TracingCode.md Outdated Show resolved Hide resolved
tutorials/ab3TracingCode.md Outdated Show resolved Hide resolved
tutorials/ab3TracingCode.md Outdated Show resolved Hide resolved
tutorials/ab3TracingCode.md Outdated Show resolved Hide resolved
tutorials/ab3TracingCode.md Outdated Show resolved Hide resolved
tutorials/ab3TracingCode.md Outdated Show resolved Hide resolved
tutorials/ab3TracingCode.md Outdated Show resolved Hide resolved
tutorials/ab3TracingCode.md Outdated Show resolved Hide resolved
Copy link
Contributor

@JiaXinEu JiaXinEu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how this provides a better understanding of the interaction between command and model.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think the arrows for method call should be solid lines instead of dashed lines (since those indicate returns)
eg.

EditCommand -> Model : setPerson(person, editedPerson)

Additionaklly, perhaps the call to setPredicate can be ommitted?

Copy link
Author

@UdhayaShan1 UdhayaShan1 Jul 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Yep your right, was a mistake to put dotted arrow

  2. Yes seems unnecessary, I will remove that call

Thanks!


[<-- EditCommand
deactivate EditCommand

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested:
image

Changes:

  1. Moved FilteredPersonList out of Model. Although the class is in the Model, and the object is kept as a variable inside ModelManager, it simply acts as a data transfer object between the two components. So, better to show outside of both components. This also solves the problem of more than one component showing low-level details (as the Model now does not show low level details).
  2. Added object names, semicolon before class name
  3. Used solid arrow for method calls
  4. Show parameters and return values where useful
  5. Removed setPredicate(...) as that's an internal detail of the Model.

You can tweak further, as needed.

@startuml
!include ../style.puml
skinparam ArrowFontStyle plain

box Logic LOGIC_COLOR_T1
participant ":EditCommand" as EditCommand LOGIC_COLOR
participant "r:CommandResult" as CommandResult LOGIC_COLOR
end box

participant "filteredPersons:FilteredList<Person>" as ObservableList MODEL_COLOR
box Model MODEL_COLOR_T1
participant "model:ModelManager" as Model MODEL_COLOR
end box

-> EditCommand : execute(model)
activate EditCommand



EditCommand -> Model : getFilteredPersonList()
activate Model
Model --> EditCommand : filteredPersons
deactivate Model


EditCommand -> ObservableList : get(index)
activate ObservableList
ObservableList --> EditCommand : personToEdit
deactivate ObservableList

EditCommand -> EditCommand : createEditedPerson(personToEdit, editPersonDescriptor)
activate EditCommand
EditCommand --> EditCommand: editedPerson
deactivate EditCommand

EditCommand -> EditCommand : check for duplicates
activate EditCommand
deactivate EditCommand

EditCommand -> Model : setPerson(personToEdit, editedPerson)
activate Model
Model --> EditCommand
deactivate Model

EditCommand -> Model : updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS)
activate Model
deactivate ObservableList
Model --> EditCommand
deactivate Model


create CommandResult
EditCommand -> CommandResult
activate CommandResult
CommandResult --> EditCommand
deactivate CommandResult

[<-- EditCommand: r
deactivate EditCommand

@enduml

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Prof, will update existing puml with this and work on it as needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I will omit the arguments as it can referred in the code and will not come out too overwhelming

@UdhayaShan1
Copy link
Author

Updated according to @NeoHW ,@JiaXinEu and @damithc comments

Thanks!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generation of a CommandResult object could possibly also be labelled with CommandResult( ) to signify that we are calling its constructor. a "Cross" could be added after CommandResult returns in the diagram to signify that it is later on dereferenced and is left for garbage collection.

All in all, good job generating this sequence diagram and I hope my comments find you well and lets remember these annoying nitty gritty details as they would make UML diagrams much easier for us to generate and understand in the future.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion but I think its best to leave out the deletion here as CommandResult wont be deleted until far later until MainWindow utilises its getFeedback()

Appreciate the feedback

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, and it's always good to clarify when an object is "destroyed" especially to new students who are unfamiliar with the concept. Thanks for your kind response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants