我在网站上有标签:电影院,音乐会,俱乐部,剧院,儿童,其他。每个标签显示适当的事件和时间表。 这是我的目标:
对于电影:
Film
,Cinema
,CinemaSchedule
剧院:
Performance
,Theater
,TheaterSchedule
等。组织业务对象和代码复制
现在考虑演唱会:
Concert
,ConcertPlace
,ConcertPlaceSchedule
。
但这是不正确的,因为音乐会可能在俱乐部或剧院(例如)。 同样的情况是俱乐部。有不同的事件发生:音乐会和派对。
那么,什么是组织类的最佳方式?另一个例子:我们有电影“穿靴子的猫”。一方面是这部电影,另一方面是卡通片(儿童片)。现在电影出现在“电影”和“儿童”中需要创建两次。
还有一个问题,我将展示的例子。
This is my repository for `Film`:
public class FilmRepository:BaseRepository<Film>
{
public FilmRepository(DatabaseContext database) : base(database)
{
}
/// <summary>
/// Loads films for specific period
/// </summary>
/// <param name="period"></param>
/// <returns></returns>
public IList<Film> GetFilmsForPeriod(PeriodEvent period)
{
switch (period)
{
case PeriodEvent.All:
return GetAllFilms();
case PeriodEvent.Today:
return GetFilmsForToday();
case PeriodEvent.Tomorrow:
return GetFilmsForTomorrow();
case PeriodEvent.Week:
return GetFilmsForWeek();
case PeriodEvent.FewWeek:
return GetFilmsForFewWeek();
case PeriodEvent.Month:
return GetFilmsForMonth();
case PeriodEvent.FewMonth:
return GetFilmsForFewMonth();
default:
return GetFilmsForToday();
}
}
// load films for today
private IList<Film> GetFilmsForToday()
{
return
Database.Films.Where(c => c.CinemaSchedules.Any(s =>
s.ShowDate.Value.Date == DateTime.Now.Date)).ToList();
}
//implementation another methods from above.
}
而且每个存储库都有相同的方法。 CinemaSchedule
的一个区别是TheaterSchedule
(或ClubSchedule
,等等)。
如何避免此重复?
谢谢,对不起我的英语。