Search code examples
umldiagramclass-diagramsequence-diagram

Delete message in Sequence diagram MVC


The below image is a sequence diagram for deleting a user out a users list page (UsersView). Once the user clicks a delete button of a user row in the Users View, I'm supposed to delete that specific user and update the Users View. My question is when deleting, in my sequence diagram, should I point the delete message to a User Model (meaning that a user model will be deleted) or is my diagram below fine as it is where I use the method message deleteUser() and basically deletes the relevant selected model from the whole Users Model.

enter image description here

Would appreciate if someone could clarify this.

Cheers!


Solution

  • Since there is an operation deleteUser() exposed from UserModel I would suppose that this class manages a list of users (likely User objects) and it would therefor delete one of those. Whether or not you want to show the deletion of that very object depends on which detail you need/want to show. If it's crucial to show the deletion of the User object you could show an additional Delete message towards another User lifeline. The «destroy» in any case looks wrong since you do not send a deletion message towards UserModel to end its life but just send a normal message.

    Hmm. Maybe your UserModel is the User itself? In that case you should think about better naming of your model elements. Though MVC seems to imply you call your classes with the according postfix I don't think that's a good idea for the M. Have you ever seen a data model where each class is postfixed with Model?


    A bit more about deletion. I ran through the specs and found these paragraphs below chapter 17.4 Messages:

    enter image description here

    [...]

    • An object deletion Message (messageSort equals deleteMessage) must end in a DestructionOccurrenceSpecification.

    A deleteMessage is an attribute of the MessageSort enumeration:

    • deleteMessage The message designating the termination of another lifeline.

    So that's about it. There is no mention of a stereotype or keyword to be used. It would be a plain message (arrow) followed by the X to mark the end of object life.

    enter image description here

    So that leaves a bit space for interpretation. However, there is not mention to have a stereotype/keyword «destroy» along with the message. If you send with a signature that operation would be called and the object would have to destroy itself after finishing. And as written it's the termination of another lifeline which when invoking an operation would contradict as it would need to destruct itself afterwards.


    Personally I would not show the object and its destruction unless it is important (for memory management and/or security). The ìnitiateDeleteUser() (again a bad name since it does really delete the user) would be enough here.