I was wondering how one would implement a UML diagram like this in Java? Is it optional to enter the things below the enum part, or would that be required as well as the enum?
-
3Have you tried to implement it yourself?– LinoCommented Apr 26, 2019 at 10:53
-
BTW the diagram doesn't look like UML class diagram. There should be only 3 compartments with class, attributes and operations (uml-diagrams.org/class.html) and not 4!– xmojmrCommented Apr 26, 2019 at 11:00
-
1@xmojmr No. See p. 726 of UML 2.5: compartment : UMLCompartment [0..*]– qwerty_soCommented Apr 26, 2019 at 11:09
-
What should that comparment below the name comparment mean? Looks sort of operations, but a bit strange parameters.– qwerty_soCommented Apr 26, 2019 at 11:11
-
2The information in brackets apparently matches the attributes structure. It's just an educated guess but it seems that (for UserType) enum value Admin has attribute values: name = "System Administrator", id=6, numberOfAllowedBooksToBorrow=30.– IsterCommented Apr 26, 2019 at 12:05
1 Answer
Visibly the diagram uses an extended drawing where the first compartment give the 'standard' enum item names more the associated value of the attributes, the second compartment are of the attributes, the third of course the operations. (In BoUML I preferred to draw items and attributes in the same compartment fo respect UML standard)
Because it is an enum the constructor must be private rather than public, this is an error in the diagram
Is it optional to enter the things below the enum part, or would that be required as well as the enum?
The attributes have to be set, and the attributes/operations defined, a possible definition of UserType is :
public enum UserType {
Student("Under Graduate Student", 1, 20),
PostStudent("PostGraduate Student", 2, 30),
AdminStaff("Administrative Staff", 3, 30),
Librarian("Librarian", 4, 40),
AcademicStaff("Academic Staff", 5, 40),
Admin("System Administrator", 6, 30);
private String name;
private int id;
private int numberOfAllowedBooksToBorrow;
private UserType(final String n, int i, int nb) {
this.name = n;
this.id = i;
this.numberOfAllowedBooksToBorrow = nb;
}
public String getName(){ return name; }
public int getId(){ return id; }
public int getNumberOfAllowedBooksToBorrow(){ return numberOfAllowedBooksToBorrow; }
public String toString(){ return name; }
}
The same way can be used for PermissionType