代码之家  ›  专栏  ›  技术社区  ›  ADringer

领域驱动设计中的用户界面信息

  •  1
  • ADringer  · 技术社区  · 7 年前

    event (如生日、聚会等)。

    事件有开始和结束日期,因此有如下模型:

    public class Event
    {
        private DateTime _startDate;
        private DateTime _endDate;
    
        // methods omitted for brevity
    }
    

    现在在显示开始和结束日期的UI部分,用户可以选择背景颜色。这可以添加为:

    public class Event
    {
        private DateTime _startDate;
        private DateTime _endDate;
        private Color _dateColor;
    }
    

    对于UI的每个部分(location部分可以有一个颜色,等等),这可以重复很多次。

    public class Event
    {
        public EventDates EventDates { get; private set; }
    }
    
    public class EventDates
    {
        private DateTime _startDate;
        private DateTime _endDate;
        private Color _dateColor;
    }
    

    有什么想法吗?

    2 回复  |  直到 7 年前
        1
  •  1
  •   RandomUs1r    7 年前

    我会在考虑可伸缩性和封装的情况下这样做:

    public class Event
    {
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
        public EventDisplayOptions DisplayOptions { get; set; }
    }
    
    public class EventDisplayOptions
    {
        public Color DateBackgroundColor { get; set; }
        public Color SomeOtherFieldColor {get; set; }
    }
    
        2
  •  0
  •   Nitin babariya    7 年前
    • 在同一事件中是否需要将日期和显示颜色配对?

    • 是否可以使用单独的配置来配置显示颜色,而不是在事件中显式指定?

    如果不同类型事件的颜色可以完全单独配置,那么我建议在单独的对象中保留显示颜色相关信息。