好的,我已经负责这个 RESTful 架构的服务器和客户端(内部使用)部分。(使用restlet)。
我们有一个公开 Post 操作的资源。这是一个简化版本:
public class UserResource {
@Post
public Representation create(UserRegistration registration) {
SomeService.getInstance().createUser(registration);
return new XstreamRepresentation(new RegistrationResponse(registration.getUniqueCode()););
}
几个月来,我们一直是唯一使用这些服务的人,因此域对象在客户端和服务器端共享......而且它工作得很好。
现在我们必须记录这些资源并让其他客户使用它们,一些“问题”已经出现,让我觉得这个 API 可能有点太复杂了。
例如,此 Post 服务。内部方法接受复杂类型UserRegistration
public class UserRegistration implements Serializable {
private Profile profile;
private Boolean someBooleanProperty;
public UserRegistration(Profile profile) {
this(profile, true);
}
public Profile getProfile() {
return profile;
}
public boolean isSomeBooleanProperty() {
return someBooleanProperty;
}
}
反过来,它使用另一个复杂的对象(配置文件)
public class Profile {
private String nickname;
private String email;
private String password;
private String firstname;
private String lastname;
private Date birthDate;
private String phone;
private Address address;
private GenderType gender;
private String subscriptionSite;
private Date privacyAcceptanceDate;
private Date subscriptionDate;
private String activationCode;
private String socialSecurityNumber;
...
它使用了很多复杂的类型等等。
这种复杂类型的使用是真正困扰我的地方。我要么不知道如何记录这一点(除了制作一长串这些复杂对象的内部属性),要么我迷路了。
我的问题是:我必须简化吗?这种架构设计得很糟糕吗?一些构建器方法可以解决问题吗?