[geos-devel] GeometryFactory - call for explanation

Mateusz Łoskot mateusz at loskot.net
Thu Mar 30 20:45:25 EST 2006


Martin Davis wrote:
> Those assumptions are correct. There were two main reason for 
> designing the GeometryFactory concept:
> 
> 1) Provide a convenient, single location for defining the various 
> "initial conditions" for Geometries.

Yes, that's what factory pattern is for.

> 2) Reduce the memory overhead of Geometries by moving relatively 
> static objects (references) out of the Geometry and into a single 
> shared object.
> 
> Hopefully this makes sense... But if anyone has good opinions about 
> another design pattern, send them along.

I'd like ask question related to the second point.

Do you mean that another option would be to create one single (global?)
and shared factory?

If you do, then I'd say this stays in opposition to the assumption nr 3:

"3. It is not assumed that all geometries share the same common instance
of GeometryFactory"


We, with Sandro, are considering possible improvements related to
managing and track lifetime of object like those factories.
So, if my 3 assumptions I presented are correct, and they are as you've
confirmed already, then here is my proposal:

I'd suggest to use "Shared Smart Pointer" semantic to manage geometry
factories and their relations to geometry objects.
One possibility is to use boost::shared_ptr (no linking to ext. libs
required, just including one header, as <vector> or <list>).

Why?

1. Using shared_ptr we don't have to track which factory is assigned to
which geometry.

2. Using shared_ptr we don't have to track where is particular factory used.

3. Using shared_ptr it is guaranteed that GeometryFactory object lives
as long as it is required and no longer.

Why not to use singleton or when to use it?

Singleton is another option but *does* *not* apply to the current
design, according to assumptions already confirmed.

There is rationale to implement GeometryFactory as a Singleton *only* if
it is assumed that there is only *one* factory and it is common to all
instances of Geometry class. But this situation does not occur as I
understand (and 3 assumptions confirm).

strk:
How are you convinced to move to smart pointers?

Cheers
-- 
Mateusz Łoskot
http://mateusz.loskot.net



More information about the geos-devel mailing list