对象建模问题 [英] Object modelling problem
问题描述
我有汽车课,每个课都有附加物品清单(皮革,腹部,折叠镜等)
I have got class Car, and each class has list of extras (leather, abs, Folding mirrors etc...)
public Extra
{
public bool Paid {get;set;}
public string Name {get;set;}
public string Code {get;set;}
}
现在,更好的是:
class Car
{
public Extra Leather {get;set;}
public Extra FoldingMirrors {get;set;}
public Extra Abs {get;set;}
}
或更好:
class Car
{
private List<Extra> _listOfExtras=new List<Extra>
public List<Extra> ListOfExtras
{
...
}
}
最糟糕的是:
我的winforms应用程序可以脱机工作,并且每月有一个正在为我发送数据.
My winforms application works offline and one per month is sending datas for me.
我必须保留此应用程序中可用(每个汽车用户选择的配件)配件的列表,因此我认为更好的方法是选择之一.
I must hold list Of available (foreach car user choose extras) extras in this application so better way I think is option one.
如何在我的应用程序中保留此附加清单?它每月仅与Web服务连接一次.
how hold this list of extras in my applications ? It connect with webservice only one time per month.
推荐答案
附加内容的列表或字典(以便于访问)会更加灵活.
A list or dictionary (for easier access) of extras would be more flexible.
这意味着随着附加功能在汽车中的添加和/或移除,您无需修改Car
类,而如果明确添加了每个类,则无需进行修改.
It would mean that as extras were added and/or removed from a car you wouldn't have to modify the Car
class which you would have to do if each were added explicitly.
有多种方法可以在本地存储列表.您可以序列化为文件-纯文本或XML,这会更好,因为您拥有可以为您进行序列化的类,或者可以将其保存在本地数据库中.
There are various ways to store the list locally. You could serialise to a file - either plain text or XML which would be better as you've got classes that do the serialisation for you, or you could hold it in a local database.
这篇关于对象建模问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!