开发者

Data model, generic containers, C++

I am writing a new container as an extension of common STL containers stored in AContainer (an abstract class). For this container I want to add new features depending on stored objects (geometric objects like points, lines, ...)...

But the problem is 开发者_如何学Pythona little more complicated. For example... There are several types of points (2D, 3D...), most properties are the same ... Which data model is more appropriate:

1) Universal Container

A derivation of the new class Container from abstract class AContainer common for each type of objects.

AContainer -> Container

Perform partial specialization for other geomeric objects

Container <Point>
Container <Edge>
Container <Polygons>

and implement their behavior inside those classes.

But this model brings troubles with the desciption of the same behavior of different types points. I have to specialize Container for Point2D, point3D

Container <Point2D>
Container <Point3D>

and in both specialization write their behavior, so a lot of code will be duplicated.

In C++ is, in my opinion not possible to do partial specialization for class and all derived classes.

2) Specific container for each type of object

A derivation of new classes for each type of object

AContainer ->ContainerPoints
           ->ContsinerEdges
           ->ContainerFaces

There are several different containers that could be specialized. The problem with the description of points behavior will not occur, their common properties will be defined inside

ContainerPoints

without need for any specialization...

I'm afraid of too much fragmentation of the code (too much similar classes)... And for example std::vector is universal for each stored type...

Is it better for each geometric type to create a new class or to do a partial specialization?

Thanks for your help...


How about this:

  template<class T>
  class Container { ... };
  class PointContainer : public Container<Point> { };
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜