Re: Confusion about splitting classes to allow sharing of resources
- From: "H. S. Lahman" <h.lahman@xxxxxxxxxxx>
- Date: Thu, 21 Apr 2005 17:07:00 GMT
Responding to M.a.stijnman...
First of all, thanks for the elaborate answer, you gave me a few things to think about. I think I also see one of the flaws in my thinking here. Let me explain a little on how I have a spline implemented now (without going into the mathematics). Basically, it holds a vector of strictly increasing knots t[i], and a vector of corresponding function values f[i]. It can also act as a function f(t), which returns the interpolated values at a certain t. Also, it can calculate an approximate derivative f'(t). Indeed one can imagine different interpolation schemes, like linear and cubic interpolation, using the same interface. I think where my thinking got flawed, is that I use spline objects to actually *store* the data that needs interpolation.
I agree with the flaw for a number of reasons. As you note, lots of different algorithms can be applied to the same data. Sorting out and selecting algorithms is a good job for patterns like Strategy. That allows the selection of the algorithm (i.e., dynamically instantiating the relationship) to be separated from the routine computations. Generally that selection will require an understanding of the context that is beyond what the individual objects involved in a specific collaboration need to know about (i.e., they have there own problems to resolve).
Separating the data also allows one to apply parametric polymorphism. One encodes more generic algorithms and allows detailed problem differences to be described in data. That, in turn, allows the problem structure to be define in external configuration data rather than being "hard-wired" in the code. Separating the data also allows one to capture the details of the problem in static structures. For example, the number of knots and function values can vary from one problem to the next while the algorithms remain the same (i.e., they "walk" the data collections in exactly the same way).
Whenever some of the data is changed, the spline object sets a flag so that when next time interpolation is performed, the 'behind-the-scenes' interpolation data gets regenerated. What you are telling me here, if I understand correctly, is I should think of spline as an algorithm, rather than as an object. Probably my data to be interpolated should then also be stored outside of the spline instance. Is that right?
Maybe. B-) I'm not advocating functions as first class objects so one still has objects for the algorithms a la the Strategy pattern. What I am advocating is separating the concerns and encapsulating them in multiple objects. Then use the relationship structure instantiation to define the specific problem. So in that sense your conclusion is correct; delegate the data responsibilities elsewhere and isolate the algorithms that may be substituted for processing the data.
I think the schema can be a little simplified in my case, since both the position (x,y) as the parameters p and q are modelled as a parametric function of a single parameter t. The exact shape of the function is determined by the values of x, y, p and q at the curve nodes, as well as the value of t defined at the curve nodes. This vector t[i] is what I refer to as the knot vector and is what is used to build the splines. So there is only one knot vector, even though each variable can have it's own type of interpolation.
OK. I inferred you were looking for something more versatile where one could add other properties besides p and q in a fairly arbitrary manner. If not, you only need one data holder class for the curve points.
As for the adding of nodes and knots, you're saying that should be handled by whatever class wants to instantiate a Curve or a Spline, right? Especially for the splines that makes much more sense if I see the spline class as an algorithm on outside data, not as an object holding data. So I should write a SplineFactory class, and a CurveFactory class, to provide that sort of facilities, correct? I think I'll read up on factory classes a bit then, figure out how best to implement them.
Yes, pretty much. I think the problem is complicated enough to warrant separating the concerns of constructing the overall structure into a dedicated object(s). This is especially true if you use data holders and relationship collection classes for your [i] data. That object can understand and encapsulate the rules for properly instantiating the relationships.
I am not sure you need a bunch of factory objects (e.g., one for each class), though. It seems like the structure is pretty fixed for a given curve. In that case it is pretty much just a succession of constructor calls. IOW, it is complicated enough to encapsulate in a dedicated object but not so complicated that it needs to be delegated among multiple objects. The main decision seems to be determining the right algorithms to use given the Curve type. If that is not too complicated, it might be easier to jam it all in a single factory's method.
[You may not need the polymorphism that the GoF construction patterns provide, though; you may just need a "hard-wired" variation on the concreteFactory object. The GoF patterns are all geared to dealing with a situation where one needs to select the right factory based on some dynamic context. You pretty much know exactly what needs to be instantiated as soon as you get a particular Curve in hand.]
************* There is nothing wrong with me that could not be cured by a capful of Drano.
H. S. Lahman hsl@xxxxxxxxxxxxxxxxx Pathfinder Solutions -- Put MDA to Work http://www.pathfindermda.com blog: http://pathfinderpeople.blogs.com/hslahman (888)OOA-PATH
.
- Follow-Ups:
- Re: Confusion about splitting classes to allow sharing of resources
- From: m.a.stijnman@xxxxxxxxxxxxxx
- Re: Confusion about splitting classes to allow sharing of resources
- References:
- Confusion about splitting classes to allow sharing of resources
- From: m.a.stijnman@xxxxxxxxxxxxxx
- Re: Confusion about splitting classes to allow sharing of resources
- From: H. S. Lahman
- Re: Confusion about splitting classes to allow sharing of resources
- From: m.a.stijnman@xxxxxxxxxxxxxx
- Confusion about splitting classes to allow sharing of resources
- Prev by Date: Re: Is there a BEA Tuxedo equivalence in Java?
- Next by Date: Re: audit log on normalized data
- Previous by thread: Re: Confusion about splitting classes to allow sharing of resources
- Next by thread: Re: Confusion about splitting classes to allow sharing of resources
- Index(es):
Relevant Pages
|