[Gdal-dev] GDALDataset as a Base Class

Mateusz Loskot mateusz at loskot.net
Tue Aug 29 23:11:05 EDT 2006


Matt Hanson wrote:
> Interesting, my original implementation had GDALDataset as a private
> member as you suggest.   As I spent more time thinking about it I
> thought that a derived class would be better in the long run, so I
> started looking into what was required for that.

Matt,

...I'm back from dog walk so last reply today before going to bed :-)

Please, be aware that my reply refers to a general idea/concept,
and I likely have not considered design requirements of your project.
So, it's a kind of brainstorm from my side.

I assumed that:
- you want to avoid playing with pointers if it's possible
- you want to simplify GDAL dataset to form of image (to access
its bands, and other properties)

with these points in mind, I'd use composition.
BTW, to avoid misunderstanding, I use 'composition' term
according to this explanation:
http://ootips.org/uml-hasa.html

> As it turns out
> though I had already come to the conclusion that my GSBand class
> would have to use GDALRasterBand as a private member because of
> course you can't create raster objects directly.

Similarly to discussion above, everything depends on what is the
relation between GDALRasterBand and GSBand.
What does GSBand with the GDALRasterBand do?
Is GSBand is going to be a kind of Facade Pattern
(http://en.wikipedia.org/wiki/Facade_pattern)
that will offer realization of the same concept as GDALRasterBand,
but with simplified interface (e.g. tighter subset of functions, etc.)

Another option is taht GSBand will *extend* GDALRasterBand
functionality. In this case I'd consider inheritance.

Yet another variation possible is that may be your GSBand and other GS*
classes are going to enable users to play with values and references,
instead of pointers.

Yet more another option is that may be GSBand (and other GS* classes)
are needed to be an adapter around GDAL API (Adapter Pattern -
http://en.wikipedia.org/wiki/Wrapper_pattern)
adapting it to your system interface, etc.

> I suppose at the
> very least it makes sense to have them use the same design, thus
> GDALRasterBand and GDALDataset as private members.

I just want to say, I'm speculating a bit saying "I'd use encapsulation
over inheritance" because everything depends on your objectives.

> Thanks for the explanations, it's been a tremendous help!

I'm happy to hear I'm able to help someone with something!

Cheers
-- 
Mateusz Loskot
http://mateusz.loskot.net



More information about the Gdal-dev mailing list