[LC++]Pure base class as a friend

Mark Phillips mark at austrics.com.au
Mon Sep 10 13:41:17 UTC 2001

Jan Reimers wrote:
> Mark,
>     Can you classify the sorts operations a manipulator would do?

I should make it clear that my "point on a sphere" example is an
example of the _kind_ of thing I want to be able to do.  I chose
this example because it is easy to illustrate the issues with.

Suppose you want your program to be able to search the surface of
a planet, looking for a point which satisfies certain criteria.
For example, you might want to look for a point on the Earth
surface which is ocean, is approximately a certain distance from 
land, and with temperature then being within certain bounds.
A manipulator would move a point along the surface of the
sphere in some specified way, and as it did, would ascertain
whether one or more conditions were met.  Different manipulators
might have different ways of moving a point around on the
surface, and might be looking for different point criteria.

At different times in the program, we might want to look for 
different points.  We might also want to examine points on 
different planets.

The program might implement this search for a point using an object
"sphereSearcher".  All this object knows, is that it has some
sphere, given to it at construction time, and several point
manipulators of various kinds, which it must use to find a
suitable point on the sphere.  It doesn't know what planet it
is dealing with.  It doesn't know the specifics of how points
are to be manipulated (varied) in the search.  It might know
that one type of manipulator varies points by following a 
satelite orbit, and that another type of manipulator changes
position randomly, but there are lots of details which are hidden
from the sphereSearcher object.  The sphereSearcher object uses
different manipulators in sensible ways in order to find a suitable
point.  It will switch a point object between different manipulators
as part of the search process.  It is this need to switch a point
(or possibly several points) between different manipulators which
means the manipulator object and the point object cannot be combined
into a single object.

The manipulator class is actually a base class.  It will be used
to provide an interface into the sphereSearcher object.  The
sphereSearcher object only needs manipulators with certain 
functionality, such as the ability to move a point, and the 
ability to determine if one or more criteria are satisfied by
a point.  All the details of precisely how to move the point
around and how criteria are to be calculated are of no consequence
to sphereSearcher and so should be left outside the sphereSearcher
object.  Base class objects are a way of specifying such an interface
and leaving implementation details outside the sphereSearcher class.

Such an implementation allows the sphereSearcher object to have a
generic quality.  It can work with a variety of different planets
and a variety of different point manipulation strategies and a 
variety of different point searching requirements.

Well, I don't know how well this has explained what I am trying
to do, but hopefully it gives you a better idea.  I suspect my
methodology is the right one to give me what I want, though
perhaps there is another way??



More information about the tuxCPProgramming mailing list