gpt4 book ai didi

c# - 哪种设计模式最适合足球比赛应用程序

转载 作者:行者123 更新时间:2023-11-30 23:11:10 25 4
gpt4 key购买 nike

我正在为支持足球队从比赛中收集统计数据的应用程序创建 Web API。我现在正处于实现阶段。假设我在想什么(如果需要)类型的设计模式最适合这样的事情:

 public class Shot
{
public int Id { get; set; }
public int PlayerId { get; set; }
public string Comment { get; set; }
public bool OnGoal { get; set; }
public int GameId { get; set; }

}

public class Card
{
public int Id { get; set; }
public int PlayerId { get; set; }
public string Comment { get; set; }
public bool IsRed{ get; set; }
public int GameId { get; set; }
}

如您所见,有些属性是相同的。它应该通过接口(interface)、继承(例如 Action 类)来实现,或者我应该使用一种设计模式(哪一种)?什么最适合 Entity Framework 以避免在后期阶段出现问题?

最佳答案

那么,您的两个类都代表某种游戏事件 - 击球和纸牌。可能还有其他一些比赛事件,例如任意球、掷界外球、换人、罚球或角球。所有这些事件都应该有 id、游戏 id、玩家 id、时间戳和可能的评论。所以你的问题是几个类中的数据重复。用继承很容易解决。无需模式:

public abstract class GameEvent
{
public int Id { get; set; }
public int GameId { get; set; }
public int PlayerId { get; set; }
public TimeSpan Time { get; set; }
public string Comment { get; set; }
}

以及各种具体事件

public class Shot : GameEvent
{
public bool OnGoal { get; set; }
}

public class Card : GameEvent
{
public bool IsRed { get; set; }
}

您还应该考虑保存添加时间的时间戳,因为您可以获得 46 分钟的时间跨度(下半场开始)和 45+1 分钟的上半场。

关于c# - 哪种设计模式最适合足球比赛应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44913263/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com