Re: How to model decoupled hierarchies?
- From: "H. S. Lahman" <h.lahman@xxxxxxxxxxx>
- Date: Fri, 17 Nov 2006 17:28:57 GMT
Responding to Kowalski...
Seems even simple things can turn out to be difficult to explain :)
There is just one typ of object. There is no polymorphy involved in the
object model.
Therefore I mean the following:
class Object {
private:
std::vector<Slice> _slices;
...
}
class Slice {
private:
std::vector<Countour> _contours;
...
}
class Contour {
private:
std::vector<ObjVertice> _objVertices;
...
}
class ObjVertex {
public:
double x,y,z;
}
Means an object contains a lot of slices. Each slice contain a lot of
contours. Each contour a lot of object vertices. With hierarchy I just
wanted to express a "folder-like" structure. The "..." just symbolize
that there are more properties then just the arrays.
OK, so the vectors are just instantiating 1:* relationships that break down a particular problem space structure that happens to be hierarchical. And...
My algorithm takes an object as input and generates the surface as
output. The surface is the second hierarchy and looks like this:
class Surface {
std::vector<SurfaceSector*> _sectors;
// maybe: std::vector<PerSliceElements> _sliceElements; // Does this
belong here??
}
// Since the surface sector object embodies the "business logic"
// there might be also different types of surface sectors.
class SurfaceSector {
Slice & _lowerSlice; // alternatively: PerSliceElements &
_lowerSliceElement;
Slice & _upperSlice; // alternatively: PerSliceElements &
_upperSliceElement;
std::vector<Region> _regions;
}
class Region {
std::vector<Triangle>
}
class Triangle {
ObjVertex *a, *b, *c;
}
Another problem space structure characterized by 1:* relationships that happens to be hierarchical. Now...
// This stuff I don't know there to put:
typedef std::vector<ObjVertices> PointGroup;
class PerSliceElements {
std::vector<PerContourElements> _contourElements;
std::vector<PointGroup> _pointGroups;
// maybe: Slice & _slice;
}
class PerContourElements {
std::vector<PerObjVertexElements > _vertexElements;
// or instead of above: std::vector<SurfaceNormal> _normals;
ConvexHull _hull;
// maybe: Contour & _contour;
}
class PerObjVertexElements {
SurfaceNormal _normal;
// maybe: ObjVertex & _vertex;
}
Since I'm not familiar with the problem space, the thing I am missing is how the first structure maps into the second. Alas, that seems to be the root of your concerns as well. B-)
There has to be some systematic way to "unwind" an Object structure into ObjVertices and then "rewind" them into a Surface structure. I am guessing that is algorithmically well-defined but tedious.
My inclination would be to encapsulate that mapping algorithm in some sort of factory object that builds the entire Surface structure by "walking" the relationships of the Object in hand. So one has:
<rest of Object structure>
|
| 1
[Slice]
| *
|
| R1
|
| element of
| 1
[Object]
| 1
| walks structure of
|
| R2
|
| 1
[SurfaceFactory]
| 1
|
| R3
|
| constructs
| *
[Surface]
| 1
|
| R4
|
| *
[Sector]
| 1
|
<rest of Surface structure>
Now one doesn't need explicit relationships between Surface elements and Object elements. I think that might eliminate the need for objects like PerSliceElements. I am guessing you only need those to abstract how the two surface structures are related during the construction of a Surface from an Object. If one encapsulates the entire construction is a single method, the need for them goes away.
Even if one needs to navigate back to the Object elements (e.g., to get {x,y,z} information) from the Structure elements, one can instantiate those direct relationships as one constructs the [Surface] structure because one will have the corresponding Object element in hand. That is, the links in [Triangle] can be initialized.
[Caveat. I am making an assumption that you need the [Surface] structure to solve some customer problem (e.g., it is a basic part of some sort of 3D display rendering). That assumption allows one to separate the concerns of constructing the [Surface] structure from the concerns of navigating it.]
Since there are many millions of vertices these elements shall be as
small as possible.
The algorithm is very complex and shall be as fast as just possible.
Speed have highest priority. Second comes "memory space" and third
"maintainability".
This is another reason why I think separating the concerns of constructing the [Surface] structure from those of doing something with a Surface is a good idea. That allows the construction algorithm to be encapsulated and optimized in one place. If one can eliminate intermediate objects like PerSliceElements, then one could have substantial performance gains in both context switches and heap operations.
A downside of delegation of responsibilities is performance when the number of objects is large. Ultimately one could delegate responsibilities down to the point where each bit was an object and one could have children in the time the program executes. So at some point one needs to find abstractions where one can substitute algorithmic processing for static structure even though static structure is the basis of high maintainability in the OO paradigm.
In the OO paradigm the criteria for that cut-bait point is whether the algorithm is unique to the problem in hand. IOW, one does not want to "hide" flow of control that is important to solving the particular problem. But if an algorithm exists outside the scope of the particular problem, it is fair game for encapsulation in a single method. (I have seen an entire linear programming package encoded in FORTRAN encapsulated as a single object method.)
I think encapsulating an Object "walker" algorithm to build a [Surface] structure is a good compromise. That's because such an algorithm really doesn't affect or depend on anything you actually do with the [Surface] to solve the application problem. It is simply a mapping function for the invariants of structures that exists beyond the scope of the particular problem (i.e., the algorithm can be abstractly specified in structure terms rather than specific problem terms). IOW, it's not going to change unless you make fundamental changes to the structures themselves, so maintainability is probably not a major issue.
*************
There is nothing wrong with me that could
not be cured by a capful of Drano.
H. S. Lahman
hsl@xxxxxxxxxxxxxxxxx
Pathfinder Solutions
http://www.pathfindermda.com
blog: http://pathfinderpeople.blogs.com/hslahman
"Model-Based Translation: The Next Step in Agile Development". Email
info@xxxxxxxxxxxxxxxxx for your copy.
Pathfinder is hiring: http://www.pathfindermda.com/about_us/careers_pos3.php.
(888)OOA-PATH
.
- Follow-Ups:
- Re: How to model decoupled hierarchies?
- From: Thomas Kowalski
- Re: How to model decoupled hierarchies?
- References:
- Howto model decoupled hierarchies?
- From: Thomas Kowalski
- Re: Howto model decoupled hierarchies?
- From: H. S. Lahman
- Re: How to model decoupled hierarchies?
- From: Thomas Kowalski
- Re: How to model decoupled hierarchies?
- From: H. S. Lahman
- Re: How to model decoupled hierarchies?
- From: Thomas Kowalski
- Howto model decoupled hierarchies?
- Prev by Date: Re: Events
- Next by Date: Re: Events
- Previous by thread: Re: How to model decoupled hierarchies?
- Next by thread: Re: How to model decoupled hierarchies?
- Index(es):
Relevant Pages
|