我正在创建一个应用程序来尝试 DDD。
该应用程序用于租借电影,我的课程是:
class Movie{
String title
String descrition
}
class Customer{
String username
}
class Rent{
Film film
User user
Period period
}
对于我对 DDD 的了解,我还RentService
需要创建一个Rent
对象。所以我有:
class RentService{
Rent rentMovie(User user, Film film, Date from, Date to){
//validation check (like if the film is already rented)
return rentRepository.store(new Rent(user, film, from, to));
}
}
最后,RentService
只需创建一个新Rent
对象,然后使用存储库将其存储。这是正确的吗?
然后,我想为RentNow 提供一个按钮!在从今天起租用 3 天的 Web 应用程序中,我应该添加一个计算天数的方法rentNow
,RentService
还是可以重新使用旧方法并在 Controller 类中计算该日期?