发帖    主题    评论    推荐    标签    作者    订阅    查搜    注册   登陆   关注
 
面向对象 设计模式 领域驱动设计 企业架构 框架 开发教程 微服务 大数据 扩展性 并发编程 事件驱动 分布式 SOA

这样一个领域模型设计究竟好不好?

    
2008-07-03 09:46
赞助商链接

这是一个"贷款处理应用"中的Borrower模型,一个DDD的应用(来自LoanAppDomainDrivenDesign)。

@Entity
public class Borrower {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long borrowerId;

private String borrowerType;

private String firstName;

private String lastName;

private String phoneNumber;

private String emailAddress;

private long loanId;

@Autowired
@Transient
private BorrowerRepository borrowerRepository;

public void setBorrowerRepository(BorrowerRepository borrowerRepository) {
this.borrowerRepository = borrowerRepository;
}

/**
* @return the borrowerId
*/

public long getBorrowerId() {
return borrowerId;
}

/**
* @param borrowerId the borrowerId to set
*/

public void setBorrowerId(long borrowerId) {
this.borrowerId = borrowerId;
}

public String getFirstName() {
return this.firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return this.lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getBorrowerType() {
return this.borrowerType;
}

public void setBorrowerType(String borrowerType) {
this.borrowerType = borrowerType;
}

/**
* @return the emailAddress
*/

public String getEmailAddress() {
return this.emailAddress;
}

/**
* @param emailAddress the emailAddress to set
*/

public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}

/**
* @return the phoneNumber
*/

public String getPhoneNumber() {
return this.phoneNumber;
}

/**
* @param phoneNumber the phoneNumber to set
*/

public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}

/**
* @return the loanId
*/

public long getLoanId() {
return this.loanId;
}

/**
* @param loanId the loanId to set
*/

public void setLoanId(long loanId) {
this.loanId = loanId;
}

// CRUD Methods
public void add(Borrower borrower) {
try {
borrowerRepository.add(borrower);
} catch (RepositoryException re) {
re.printStackTrace();
}
}

public void delete(long borrowerId) {
try {
borrowerRepository.delete(borrowerId);
} catch (RepositoryException re) {
re.printStackTrace();
}
}

public void update(Borrower borrower) {
try {
borrowerRepository.update(borrower);
} catch (RepositoryException re) {
re.printStackTrace();
}
}

public Borrower load(long borrowerId) {
Borrower newBorrower = null;
try {
newBorrower = borrowerRepository.load(borrowerId);
} catch (RepositoryException re) {
re.printStackTrace();
}
return newBorrower;
}
}

我有一个疑问,如此设计好不好,将一个repository放入domain object中,是否好呢?这样一来,Borrower自己可以对自己进行更新,查找等等...

2008-07-31 12:06

个人认为不好,不要以为将所有业务都塞到一个类中就是实现完整的对象了,要是这样,我们就无需设计了。

赞助商链接

赞助商链接

返回顶部

移动版 关于本站 使用帮助 联系管理员 最佳分辨率1366x768
OpenSource JIVEJDON Powered by JdonFramework Code © 2002-20 jdon.com