领域驱动设计模型

时间:2017-09-03 08:00:15

标签: domain-driven-design

我在DDD中建立 ParkingReservation ,简而言之就是人们可以邀请地点,当汽车进入相机时识别模型并更新地点的状态。
我将模型划分为三个有界的上下文:
第一个是预约上下文,包括以下对象:

`public class Lot
{
    public int ID { get; set; }
    public string Name { get; set; }
    public Address Address { get; set; }
    public List<Place> Places { get; set; }
} 

public class Place
{
    public int ID { get; set; }
    public int FloorNumber { get; set; }
    public int RowNumber { get; set; }
    public int ParkingNumber { get; set; }
}

public class Car
{
    public int ID { get; set; }
    public string Model { get; set; }
}

public class Driver
{
    public int ID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string UserName { get; set; }
    public string Password { get; set; }
    public int Age { get; set; }
    public Gender Gender { get; set; }
    public string Phone { get; set; }
    public string Email { get; set; }
    public bool AcceptAdsToMail { get; set; }
    public byte[] PictureData { get; set; }
    public DateTime RegistrationTime { get; set; }
    public DriverStatuses DriverStatuses { get; set; }
}

public class Reservation
{
    public int ID { get; set; }
    public Driver Driver { get; set; }
    public Car Car { get; set; }
    public Place Place { get; set; }
    public DateTime OrderTime { get; set; }
    public DateTime ParkingStartTime { get; set; }
    public DateTime ParkingEndTime { get; set; }
    public ParkingStatuses ParkingStatus { get; set; }
}

public class ParkingHistory
{
    public int ID { get; set; }
    public Place Place { get; set; }
    public Driver Driver { get; set; }
    public Car Car { get; set; }
    public DateTime StartTime { get; set; }
    public DateTime EndTime { get; set; }
}`

停车场有地方清单
驾驶员通过申请预留地点
保存的地方保存在Reservation对象和停车时间 已过去,新的停车历史记录添加到属于司机和汽车的停车历史列表中,因此您可以查看每辆车或司机的历史记录。
对于此预订环境:
(1)为集合根设置驱动程序和预留是否正确?还是很多呢?
(2)地点是实体还是价值对象?

谢谢

1 个答案:

答案 0 :(得分:0)

您的用例的主要目标是安排。您需要考虑围绕该想法的一致性边界。为了避免时间段重叠,你需要为此目的创建一个新的抽象。 “PlaceInLotReservations”听起来是一个很好的选择,作为一个值对象,作为Reservation聚合的工厂。为了表示调度如何工作的实际情况,您应该在一天的上下文中提供该聚合,因此“PlaceInLotReservationsRepository”应该具有“findByDate”方法,该方法收集给定日期时间内某个地点的所有预留。 所以语义就像:

09-04

如果在一个地方有很多预订,那么竞争条件你甚至可以通过在第一季度而不是一天进行初始查看来使VO变小。

BTW,can和driver是Reservation聚合上下文中的VO(它们不是聚合)。 您还可以通过查询预订存储库来获取历史记录,您不需要ParkingHistory。

希望它有所帮助。

相关问题