开发者

How to implement association class?

What is association classes, how to implement the association classes for this given model. See the screen shot

How to implement association class?

开发者_开发百科


Basically:

class GeoObjectPart
{
  public int Category { get; set; }
  public IEnumerable<GeoObjectPart> Parts { get; set; } 
}

class GeoObject
{
 public int ObjectType { get; set; } // do not use Type as a property name!
 public long Id { get; set; }
 public IEnumerable<GeoObjectPart> Parts { get; set; } 
}

And Line, Point, Area inherits GeoObjectPart class.

BTW, GeoObject.Type and GeoObjectPart.Category means the same? In such case consider some redesign because you can use single class instead of both GeoObject and GeoObjectPart

Also, few recommendations:

  • mark base class as abstract so avoid to instantiate classes which are designed to be a base
  • name base class with prefix base, like GeoObjectBase
  • consider interface for GeoObjectBase class
  • if this possible avoid public setters so instances would be immutable
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜