Supermacu
Supermacu

Reputation: 33

Entity Relationship Diagram, generalization when only one class can interact with another class

Let's imagine we have a User class, this is a generalization of two other classes: Admin and noAdmin
There is a another class to which only an Admin can interact with, let's call it only_admin

My question is, to what class should only_admin be related to? User or Admin?

ERD

Upvotes: 0

Views: 463

Answers (2)

Christophe
Christophe

Reputation: 73530

If User is associated with Something, then, all specializations of User (i.e. Admin and NoAdmin) would be associated with Something as well.

Therefore, if Something makes only sense with Admin, then make the association with Admin only and not with User. The diagram would be crystal clear and self-explaining.

Additional remarks:

  • If NoAdmin has nothing specific compared to User, you do not need to have an own class for it.
  • If things get more tricky, and User would have many more specializations, most of them being associated with Something, except a few, or if you'd have SomethingForAdminOnly which would be a specialization of SomethingForAllUsers you could have a look at this other SO question.

Upvotes: 2

bruno
bruno

Reputation: 32596

For the UML point of view as your class diagram

to what class should only_admin be related to? User or Admin?

The simpler and clearer the better, so Admin, else you have to add a constraint oclIsKindOf(Admin) or oclIsTypeOf(Admin) (see below)

Anyway if this is allowed only for instances of Admin and not for instances of possible classes inheriting Admin the constraint is required typically using oclIsTypeOf(Admin) even the relation is attached to Admin rather than User.

From Object Constraint Language / formal/2014-02-03 page 153:

oclIsTypeOf(type : Classifier) : Boolean

Evaluates to true if self is of the type t but not a subtype of t.

post: self.oclType() = type

oclIsKindOf(type : Classifier) : Boolean

Evaluates to true if the type of self conforms to t. That is, self is of type t or a subtype of t.

post: self.oclType().conformsTo(type)

Upvotes: 2

Related Questions