By an interactor I mean an object implementing a specific use case. It manipulates entities rather than inherits from them.
// entity example
package example;
import java.util.Date;
public abstract class User {
private long id;
private String name;
private String password;
private Date registrationDate;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getPassword() {
return password;
}
public String getCode() {
// application independent rule ----->
return registrationDate.getTime() + name;
}
public Date getRegistrationDate() {
return registrationDate;
}
public void setRegistrationDate(Date registrationDate) {
this.registrationDate = registrationDate;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setPassword(String password) {
this.password = password;
}
}
// interactor example
package example;
public class SetPasswordCommand {
private UserGateway userGateway;
private PasswordValidator passwordValidator;
public SetPasswordCommand(UserGateway userGateway) {
this.userGateway = userGateway;
}
public void execute(SetPasswordRequest request) {
User user = userGateway.get(request.getUserId());
String newPassword = request.getPassword();
// application specific rule
if (passwordValidator.isValid(newPassword)) {
user.setPassword(request.getPassword());
userGateway.save(user);
}
//...
}
}