Reputation: 449
I am making a class diagram of a system where a user can act as a student, instructor, or assistant. So far, I've created a user class with the following attributes, and methods, where a user can participate in a single course with a specific role, and also can remove from a particular course. Since, a user can have only one role, I've declared it in square brackets -Participant: Role [1]
.
However, it says only that a user can have one role, but it does not say the different roles of a user. How can I specify this in a class diagram. Should I make a new Role
class, or I can specify in the user
class?
USER CLASS:
Attributes:
-username: String
-password: String
-Participant: Role [1]
Methods:
+participate(course: Course, role: Role): void
+remove_user(course: Course): void
+get_average(assignment: Assignment): int
Upvotes: 1
Views: 865
Reputation: 6529
You can make Role
abstract and then create subclasses for student, instructor, and assistant. That way you can only instantiate one of the subclasses per user.
Alternatively, you can make the Role
an enumeration, where each enumeration literal is a particular instance of a Role
. That way you can instantiate one of each Role
across the entire system: student, instructor, and assistant.
In your system, should all users play the same role, or should each user in a role have additional information, such as the date the role was assigned to the user? The answer to this question tells you which alternative to choose.
BTW, isn't the limitation of a user being a student, instructor, or assistant, ever, a bit too limiting? Why couldn't a user play the role of student in one course while playing the role of an assistant in another course?
Upvotes: 2