samedi 15 avril 2017

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

Actually,I work an application about map simulation,Element represent something with id and 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();
}

And Device is something like radar or radio device,they all have id and class,so Device inherit Element:

public abstract class Device:Element
{

}  

and Target calss is something like radar station,radio station with a position property,

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();
    }
}

Position is a struct :

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

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

There is also a class named Platform inherit Target,which means a ship or a plane,they can move from one position to another.

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

    public void Move()
    {

    }
}

All these classes should be in BL,that's no problem.But in UI, Device or Target should have Color and image proerty to show in map control(GMap.net,use image to GMapMarker).For the reason of split ui from bl,image or color will not allowed in BL.The question is:

Is there some design patterns or elegant way to handle this situation?

Thanks!

Aucun commentaire:

Enregistrer un commentaire