user9821567
user9821567

Reputation:

Implementation of class diagram

https://imgur.com/a/AFL2dJF

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?

Upvotes: 1

Views: 175

Answers (1)

bruno
bruno

Reputation: 32596

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

Upvotes: 1

Related Questions