[geos-devel] good to have visitor design pattern support

Debabrata Bardhan dbardhan at gmail.com
Tue Mar 15 07:16:25 EDT 2011

I have found some future scope of enhancement of the library . Those are

1. It dosn't support Visitor design pattern

     All the classes like Polygon, Point, LineString etc all are derived
from Geometry class. If I need same operation based on different class then
I need to maintain switch cases based on GeometryTypeId.
     As per example: I want to implement a routine which will determine a
given point is moving toward or backward to those classes the my
Implementation will be

calcPosition(Geometry *g){

     switch (g->GeometryTypeId){

     Case  GEOS_POINT:
               funcForPoint(  point);          //point can be data member of
               funcForPoint( point);

The implementation is c-style and poor in maintenance since if I need one
more class to include then the switch case will be required to adjust.

If there is support of visitor in the OM then the implementation would be

calcPosition( Geometry *g,){
          //accept will be provided from OM. It should be implemented in
every class of OM
of accept:  accept( VisitorBase &v){ v.visit(this)}

class myVisitor :: VisitorBase                 //VisitorBase will be provide
from OM

          Point point;

         visit (Polygon &p)
          //point is also available;
         visit (Point &p)
          //point is also available;
         visit (LineString &p)
          //point is also available;

2.  Derive class CoordinateArraySequence can not be used directly every time
the base class CoordinateSequence has to be used in the current situation.
Need the interface to use the derive class also.

Thanks & Regards,
Debabrata Bardhan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/geos-devel/attachments/20110315/5782f6fb/attachment.html

More information about the geos-devel mailing list