Say I have a class User and an interface Administrator. Some users are administrator and can thus implement the interface. Most aren’t, however, so it’s false to say that “User implements Administrator”.
How can I represent that in a class diagram? Should I use the classic implementation arrow, or is there an existing stereotype for a class that can implement an interface?
5
What you want is a Decorator.
An Administrator would be a subclass of User, and its primary member attribute would be a User object.
Thus a Student Adminstrator would be an Administrator containing a Student (which is a subclass of User, right? The Administrator-specific attributes are set in the Adminstrator class, with the User methods passed through from the User object.
9
It makes no sense to say that a class can implement an interface. Either it does or it doesn’t, and that’s determined as the code is written. Specific instances (users) can’t make that decision for themselves, although they can set an IsAdministrator
flag instead.
If the IsAdministrator
flag is insufficient, then (as @superM said) the design you want is subclassing. A User
has some properties. Some User
are actually Administrator
, which has additional properties. Therefore Administrator
inherits from User
, and should be represented as such.