c# 当 class 有图像和颜色 属性 时我应该使用什么样的设计模式

c# what kind of design pattern should i use when a class has image and color property

其实,我在做一个关于地图模拟的应用,元素代表一些id和name的东西:

public abstract class Element
{
    public string Id { get; set; }

    public string Name { get; set; }

    public abstract void Display();

    public abstract void Stop();

    public abstract void Refresh();
}

而Device是雷达或收音机之类的东西,它们都有id和class,所以Device继承了Element:

public abstract class Device:Element
{

}  

目标类类似于雷达站,位置为 属性、

的无线电台
public class Target : Element
{
    public Position Position { get; set; }

    public List<Device> Devices { get; private set; }

    public List<Target> Targets { get; private set; }

    public override void Display()
    {
        //throw new NotImplementedException();
    }

    public override void Refresh()
    {
        //throw new NotImplementedException();
    }

    public override void Stop()
    {
        //throw new NotImplementedException();
    }
}

位置是一个结构:

public struct Position
{
    public double Lat { get; set; }
    public double Lng { get; set; }       

    public Position(double lat, double lng)
    {
        Lat = lat;
        Lng = lng;
    }
}

还有一个class命名为Platform inherit Target,意思是一艘船或者一架飞机,它们可以从一个位置移动到另一个位置。

public class Platform : Target
{
    public double Speed { get; set; }

    public void Move()
    {

    }
}

所有这些classes都应该在BL中,UI中没有problem.But,Device或Target应该有Color和image proerty显示在地图控件中(GMap.net,使用图像到 GMapMarker)。由于从 bl 中拆分 ui,BL.The 中不允许使用图像或颜色,问题是:

是否有一些设计模式或优雅的方式来处理这种情况?

谢谢!

设计模式为常见的设计问题提供通用解决方案。

我希望您遵循以下方法。

  1. 了解每个模式的意图
  2. 了解每个模式的清单或用例
  3. 想想你的问题的解决方案并检查你的解决方案是否落空 进入特定模式的清单

如果不是,请忽略设计模式并编写您自己的解决方案。 有用的链接:

https://sourcemaking.com/design_patterns:用包括 C++ 和 Java

在内的多种语言精美地解释了意图、结构和清单

wikipedia : 以多种语言解释结构、UML 图和工作示例,包括 C# 和 Java 。

每个 sourcemakding 设计模式中的检查列表和经验法则提供了您正在寻找的闹钟。

根据您的要求,我认为 Repository Design 模式最适合您。

如果您想将图像和颜色分配给一个元素,那么您可以将它们放在模型中(在您的元素 class 中)。最初它们将为空,但稍后您可以为它们赋值。我想你的模型在 BL 和 UI.

之间共享