与数据库接口的简化机制(对象持久性 框架)将有如下界面: class ObjectBroker { bool StoreObject(object obj); bool DeleteObject(object obj); bool RetrieveObject(object obj); IList RetrieveForType(类型类型); } Joanna - - Joanna Carter 顾问软件工程师 但是几乎同时存在所谓的关系数据库 对我来说似乎是基于穿孔卡的方法而且无法在一个人中使用 保存列表结构的一种方法。 之前用数据库的东西很容易做到。 因此其中一个对我来说是错误的。 (我的意见关系 数据库)。 只是我的想法, Cor Hello All,I''ve decided that this OOP thing is not just a fad. Withthat in mind, I''m desparately trying to get rid of myfunction-oriented design paradigm and switch to a moreobject-centric view of the world. Migrating some aspectsof my antiquated style has been straight-forward. For example:I used to do this:<old style>------------------------public class Widget(){public string property1;public string property2;}.... Somewhere in a "Datahandler" class:public Widget fetchWidget(int widgetid){Widget w = new Widget();.... do some database spelunking...w.property1=....w.property2=....return w;}</old style>---------------------------But now I do this<new style>----------------------------public class Widget(){private string _property1;{set{ ... etc.private string _property2;{set{ ... etc.public Widget(){}public Widget(int widgetid){this.fetchMe(widgetid);}private void fetchMe(int widgetid){.... do some database spelunking....... poulate internal vars. ...}}</new style>--------------------------But what about collections of Widgets?Continuing on from the first example above. In the same "Datahanders"class, I used to have a method like:<old style>---------------------------------------------------------public ArrayList callingAllWidgets(){ArrayList widgets = new ArrayList();.... database spelunking....foreach (whatever){Widget w = new Widget();w.property1=... etc....widgets.Add(w);}return widgets;}</old style> -------------------------------------------------------Obviously, there''s no reason I couldn''t use the same design using themore updated version (the new style) of a widget, i.e:public ArrayList callingAllWidgets(){ArrayList widgets = new ArrayList();.... database spelunking....foreach (whatever){Widget w = new Widget(foreachvalue);widgets.Add(w);}return widgets;}but this seems like cheating ;) Is there a better, more universallyaccepted superterrific way? Should i use a corresponding collectionsclass with an Indexer? Should I create some souped up IListimplemenation? I could certainly see the benefit of a class thatspecialized in providing some aggregators (i.e. add all the Widgetsproperty1 values) but this isn''t always necessary.Thanks in advance.. 解决方案You should never derive from or use ArrayList or any other general listclass. Instead you need to create typesafe list classes that only know howto manipulate (e.g.) Widgets. Of course you would use something likeArrayList inside this class but that is the only place you would have tocast from object to Widget and back again.The same principle appplies to lists as to single objects; try to separateout the database code from the business concepts. But you would possiblywant to implement IList by delegation to the internal list to allow a datamechanism to return/manipulate a common list typeA simplified mechanism to interface with databases (Object PersistenceFramework) would have an interface like this :class ObjectBroker{bool StoreObject(object obj);bool DeleteObject(object obj);bool RetrieveObject(object obj);IList RetrieveForType(Type type);}Joanna--Joanna CarterConsultant Software EngineerHowever almost the same time exist the so called relational databases whichfor me seems to been build on punchcard methods and are unable in a one toone way to hold a list structure. Something which was with databases beforethat time very easy to do.Therefore one of those is for me wrong. (My opinion the relationaldatabase).Just my thought,Cor 这篇关于OOP问题---从理论上讲......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的.. 09-08 23:47