How to implement association class?
What is association classes, how to implement the association classes for this given model. See the screen shot
开发者_开发百科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
, likeGeoObjectBase
- consider interface for
GeoObjectBase
class - if this possible avoid
public setters
so instances would be immutable
精彩评论