Admin and Client "is a" user First of all, I'd want to represent, in my application, two different users (admin and client) which can access to two different classes, through two different graphic interfaces...

My idea is to represent faithfully what is in the e/r and I'd want to generalize shared information (like nick, pw, email) using an interface and represent specific information into the two sub-classes

To store information, I use a database and a piece of the e/r is:



Now, in my code, I've implemented it in this way:

Utente entity  - represented using Interface:

package users;

/**
 * Interface which represent a general user (both admin either client)
 * 
 * @author Federico Cuozzo
 *
 */
public interface User {
    public String getNick();
    public String getPw();
    public String getEmail();
}


Admin entity  - represented using Class with Override:

package users;

import global.Globals;
import java.util.ArrayList;

/**
 * Represents the admin user instance and his all information.
 * 
 * @author Federico Cuozzo
 *
 */
public class Admin implements User {
    private String nick;
    private String pw;
    private String email;
    private ArrayList&lt;Integer&gt; authorizations = new ArrayList&lt;Integer&gt;();   // List of authorizations rwx in integer (r-- 4, rwx 7)

    public Admin(String aNick, String aPw, String anEmail) {
        this.nick = aNick;
        this.pw = aPw;
        this.email = anEmail;
        this.authorizations.add((int) Globals.r.nextInt((7-4) + 1) + 4);
        this.authorizations.add((int) Globals.r.nextInt((7-4) + 1) + 4);
        this.authorizations.add((int) Globals.r.nextInt((7-4) + 1) + 4);
    }

    // Accessor methods for private fields
    @Override
    public String getNick() { return this.nick; }
    @Override
    public String getPw() { return this.pw; }
    @Override
    public String getEmail() { return this.email; }
    public ArrayList&lt;Integer&gt; getAuthorizations() { return this.authorizations; }
}


Client entity  - represented using Class with Override:

package users;

/**
 * Represents the client user instance and his all information.
 * 
 * @author Federico Cuozzo
 *
 */
public class Client implements User {
    private String nick;
    private String pw;
    private String name;
    private String surname;
    private String email;
    private String street;
    private String city;
    private String cap;
    private String phoneNumber;

    public Client(String aNick, String aPw, String anEmail, String aName, String aSurname, String aStreet, String aCity, String aCap, String aPhoneNumber) {
        this.nick = aNick;
        this.pw = aPw;
        this.name = aName;
        this.surname = aSurname;
        this.email = anEmail;
        this.street = aStreet;
        this.city = aCity;
        this.cap = aCap;
        this.phoneNumber = aPhoneNumber;
    }

    // Accessor methods for private fields
    @Override
    public String getNick() { return this.nick; }
    @Override
    public String getPw() { return this.pw; }
    @Override
    public String getEmail() { return this.email; }
    public String getName() { return this.name; }
    public String getSurname() { return this.surname; }
    public String getStreet() { return this.street; }
    public String getCity() { return this.city; }
    public String getCap() { return this.cap; }
    public String getPhoneNumber() { return this.phoneNumber; }
}


Is this correct? Using an interface to represent main class and two concrete classes to represent sub-classes...
While the implementation looks logically correct, some remarks about code style:


package name should include your organization, e.g. com.your.company.users, com.your.company.global
there is no need to prefix arguments with a, you can use the same name as the object fields, since through this, it can be determined which one is referred.


E.g:

public Client(String nick, ...) {
    this.nick = nick;
    // ...
}