2

There are 2 classes in the scenario under consideration, User and ConnectionRequest.

The structures of the 2 classes are given below:

User:

  • fullName: String
  • username: String
  • email: String
  • password: String
  • bio: String
  • connections: Array
  • timestamp: Date

ConnectionRequest:

  • sender: String
  • receiver: String
  • message: String
  • timestamp: Date

A user can send a connection request to another user, or they can receive a connection request from another user such as on social media platforms.

What type of connection/relation do the 2 classes share?

How can this be represented using UML notations in a class diagram?

Any modifications or improvements to the above model ignoring other system requirements are welcome.

2 Answers2

1

Change the type of sender and receiver from String to User, using two associations.

Jim L.
  • 6,177
  • 3
  • 21
  • 47
1

This is tricky. If one user sends/receives a connection request to another user, but you want to use only one association, you’ll have a ternary association, with two ends for the same class User (once for the sender role, once for the receiver role) and one for the ConnectionRequest.

enter image description here

Alternative models could use either an association class ConnectonRequest of User to User, or two distinct association between User and ConnectionRequest each with a different set of roles. at both ends.

Christophe
  • 68,716
  • 7
  • 72
  • 138
  • Why would you recommend ternary? In the given scenario, I see one social media connection request that is existentially dependent on one sender and one receiver. – Jim L. Dec 21 '22 at 11:59
  • @JimL. I do not recommend ternary, but I simply answer the question “What type of connection/relation do the 2 classes share?” in which the singular implies one association, but the requirements imply that one of the parties is at more than one end of the association. Personally I’d prefer two distinct associations, and I would consider association class only if there’s a guarantee that both users are always known throughout the lifecycle of the request. – Christophe Dec 22 '22 at 09:07