lundi 28 novembre 2016

Market Interface on DTOs

I have something like this

//A marker Interface
public interface User {
}

//2 DTO Classes
public Administrator implements User{
//getters and setters
}

public OperativeUser implements User{
//getters and setters
}

//A generic interface
public interface UserService<T extends User>{
    public void createUser(T user);    
}
//Two concrete clases
public class AdministratorService implements UserService<Administrator>{
    public void createUser(T user){
       //specific stuff for an administrator
    }    
}
public class OperativeUserService implements UserService<Administrator>{
    public void createUser(T user){
       //specific stuff for an operative user
    }    
}

All this because if I write a simple UserDTO then in order to differenciate them I will end with an spagetti code like if is administrator do this and if is operative user do that, so a need to classify the users of my system as a common interface but no common behavior

So my questions are

1.-There is a better way to achieve this kind of hierarchy with composition (implements) and no with inheritance(extends) if yes could you give me some guidence?

2.- Is a good use of markers interfaces the way I did or I misunderstood?

This is base on the following questions and answers

Nice way of factory method pattern with inheritance

Interfaces for DTOs

Thank you very much!

Aucun commentaire:

Enregistrer un commentaire