-1

I am struggling how to model the class diagram. I am confused with bindings. Users can create a new dog. When the user is removed also reminders, dogs should be deleted. Isnt it composition? Memories are related to dogs, they should be deleted when the dog is deleted too. Could you help with the bindings?

enter image description here

user3637775
  • 499
  • 4
  • 20

1 Answers1

0

You are absolutely right with your assumption. A composite aggregation is shown by a filled diamond towards the aggregating class. And it's intended use is like you need it (forgot to include multiplicities):

enter image description here

As a side note:

  • your FireBaseApplication seems to be way off. There shouldn't be any class specific methods like removeDogCascade but only a removeCascaded where you can supply a class that has aggregate relations.
  • between User and Dog you should use a role name owner towards User to identify the dog's owner, rather than having a String property with the user's name (or whatever that might contain)
  • Similarly between Dog and Memory
qwerty_so
  • 35,448
  • 8
  • 62
  • 86
  • If I understand correctly I should change it everything to a composite aggregation. I will remove the Firebase Application. I assume I designed wrongly because in the code I use userId inside DogModel. I use NoSQL database and I get all dogs of user. I could add a list of dogs to the user but it won't capture reality. – user3637775 Dec 26 '16 at 21:30
  • No. Your aggregations are just fine. The role names can later be mapped to some kind of foreign key. – qwerty_so Dec 26 '16 at 23:17
  • Then I should change the binding between User and Reminder to aggregation, shouldn't I? – user3637775 Dec 26 '16 at 23:38
  • If the Reminder has a lifetime on it's own you can do so. A shared aggregation however is rather pointless ("Precise semantics of shared aggregation varies by application area and modeler.") and can well be represented by a simple association. – qwerty_so Dec 27 '16 at 09:11
  • Reminders live independetly (can be changed, removed, created..)until the user is deleted. Then they have to be deleted too. I guess it should a shared aggregation. I found a useful link http://www.cems.uwe.ac.uk/~jsa/UMLJavaShortCourse09/CGOutput/Unit4/unit4(0809)/page_15.htm – user3637775 Dec 27 '16 at 13:04
  • That actually means their lifetime is bound to the user and you should use a composite aggregation instead. – qwerty_so Dec 27 '16 at 14:06
  • Sorry, I don't know what you mean. – qwerty_so Dec 27 '16 at 17:43
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/131634/discussion-between-user3637775-and-thomas-kilian). – user3637775 Dec 27 '16 at 23:11