# Inverse OOP

**URL:** <https://www.ruby-forum.com/t/inverse-oop/135708>\
**Category:** Ruby\
**Created:** [April 24, 2008, 11:39am UTC](https://www.ruby-forum.com/t/inverse-oop/135708 "2008-04-24T11:39:58Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![martin\_gnu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/edb3f5/32.png) [@martin\_gnu](https://www.ruby-forum.com/u/martin_gnu)\
**Post date:** [April 24, 2008, 11:39am UTC](https://www.ruby-forum.com/t/inverse-oop/135708/1 "2008-04-24T11:39:58Z")

</div>

Hi:

I have always had a doubt about OOP.  
Usually we have a parent and several child, but what happen if we need  
the inverse system. for example DBI/DBD APIs.??

I need build map proyections and i want and intermediate API for all  
proyections clases.

All map proyections have the same methods (geodetic\_to\_projected and  
projected\_to\_geodetic)

Regards.

---

<div class="post-metadata">

**Author:** ![martin\_gnu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/edb3f5/32.png) [@martin\_gnu](https://www.ruby-forum.com/u/martin_gnu)\
**Post date:** [April 24, 2008, 12:16pm UTC](https://www.ruby-forum.com/t/inverse-oop/135708/2 "2008-04-24T12:16:57Z")

</div>

On 24 Apr 2008, at 10:40, Martin V. wrote:

> projected\_to\_geodetic)  
> Then define either a projection class from which they all inherit, or  
> a projection module which they all include.

Ellie

## Eleanor McHugh Games With Brains [http://slides.games-with-brains.net](http://slides.games-with-brains.net)

raise ArgumentError unless @reality.responds\_to? :reason

---

<div class="post-metadata">

**Author:** ![martin\_gnu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/edb3f5/32.png) [@martin\_gnu](https://www.ruby-forum.com/u/martin_gnu)\
**Post date:** [April 24, 2008, 11:25pm UTC](https://www.ruby-forum.com/t/inverse-oop/135708/3 "2008-04-24T23:25:42Z")

</div>

On 24.04.2008 12:15, Eleanor McHugh wrote:

> On 24 Apr 2008, at 10:40, Martin V. wrote:

> > I have always had a doubt about OOP.  
> > Usually we have a parent and several child, but what happen if we need  
> > the inverse system. for example DBI/DBD APIs.??
> > 
> > I need build map proyections and i want and intermediate API for all  
> > proyections clases.

What exactly do you mean by “intermediate”? Do you mean that all  
projections should have the same interface? For that you do not need  
inheritance at all - at least in Ruby. Or do you rather mean that they  
share behavior (implementation)?

> > All map proyections have the same methods (geodetic\_to\_projected and  
> > projected\_to\_geodetic)
> 
> Then define either a projection class from which they all inherit, or  
> a projection module which they all include.

Nice reading from you again, Ellie. 🙂

I was going to also suggest the module approach. But I do wonder why  
Martin chose to call it “inverse OOP”. It seems the more appropriate  
term would be “multiple inheritance” or am I missing something?

Cheers

robert

---

<div class="post-metadata">

**Author:** ![martin\_gnu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/edb3f5/32.png) [@martin\_gnu](https://www.ruby-forum.com/u/martin_gnu)\
**Post date:** [April 25, 2008, 1:55am UTC](https://www.ruby-forum.com/t/inverse-oop/135708/4 "2008-04-25T01:55:03Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

On Apr 24, 2008, at 11:40 AM, Martin V. wrote:

> Hi:
> 
> I have always had a doubt about OOP.  
> Usually we have a parent and several child, but what happen if we need  
> the inverse system. for example DBI/DBD APIs.??

Actually, thats quite a common problem of thought, because inheritance  
is often considered  
as _the_ problem solver in OOP. But that is not the case. I for my  
part seldomly inherit.

The core feature of OOP is composition. So even without modules, you  
could just implement  
a class that has a certain set of features and hands everything else  
to a class that has a  
concrete implementation for that task (delegation, btw. 😉 ).  
Depending on the language, this can get large because of the vast  
amount of  
boilerplate code you have to write for the delegating methods, but in  
Ruby, this is a simple task.

Regards,  
Florian G.  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.8 (Darwin)

iEYEARECAAYFAkgRHZ8ACgkQJA/zY0IIRZbPZgCgp/Vx54NYWH6PppPXRENXic3s  
OwEAn2SFwl0BnIJsu+fvc4+RUBlUGbn/  
=tD69  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![martin\_gnu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/edb3f5/32.png) [@martin\_gnu](https://www.ruby-forum.com/u/martin_gnu)\
**Post date:** [April 24, 2008, 11:45pm UTC](https://www.ruby-forum.com/t/inverse-oop/135708/5 "2008-04-24T23:45:05Z")

</div>

Robert K. wrote:

> On 24.04.2008 12:15, Eleanor McHugh wrote:
> 
> > On 24 Apr 2008, at 10:40, Martin V. wrote:
> 
> > > I have always had a doubt about OOP.  
> > > Usually we have a parent and several child, but what happen if we need  
> > > the inverse system. for example DBI/DBD APIs.??
> > > 
> > > I need build map proyections and i want and intermediate API for all  
> > > proyections clases.
> 
> What exactly do you mean by “intermediate”? Do you mean that all  
> projections should have the same interface? For that you do not need  
> inheritance at all - at least in Ruby. Or do you rather mean that they  
> share behavior (implementation)?

Same interface:

For example

This is the intermediate API  
#type=“projection=lambert, varphi\_0=45, k=1”  
type=“projection=UTM, zone=30, false\_east=40000”  
prj=Projection.new(type)

[x,y]=prj.geodetic\_to\_projected(lambda,phi)  
[lambda,phi]=prj.projected\_to\_geodetic(x,y)

This is an especific API for UTM:

parameters=UtmParameters.new  
parameters.zone=30  
parameters.false\_east=30  
prj=UtmProjection.new(parameters)

[x,y]=prj.utm\_geodetic\_to\_projected(lambda,phi)  
[lambda,phi]=prj.utm\_projected\_to\_geodetic(x,y)

This is an especific API for lambert:

parameters=LambertParameters.new  
parameters.varphi\_0=30  
parameters.k=1  
prj=LambertProjection.new(parameters)

[x,y]=prj.lambert\_geodetic\_to\_projected(lambda,phi)  
[lambda,phi]=prj.lambert\_projected\_to\_geodetic(x,y)

I have used the proj.4 C library and they used pointers to functions in  
C, in a offuscated code.

[http://proj.maptools.org/](http://proj.maptools.org/)

proj.4 use a text file like this:  
“projection=lambert, varphi\_0=45, k=1”

Every projection is an module (ANSI C file) and a only modulo know what  
module call using the text file. There are 170 different projections.

+proj=cea +lon\_0=Central Meridian  
+lat\_ts=Standard Parallel  
+x\_0=False Easting  
+y\_0=False Northing

+proj=lcc +lat\_1=Latitude of natural origin  
+lon\_0=Longitude of natural origin  
+k\_0=Scale factor at natural origin  
+x\_0=False Origin Easting  
+y\_0=False Origin Northing

+proj=tmerc +lat\_0=Latitude of natural origin  
+lon\_0=Longitude of natural origin  
+k=Scale factor at natural origin  
+x\_0=False Easting  
+y\_0=False Northing

…

> I was going to also suggest the module approach. But I do wonder why  
> Martin chose to call it “inverse OOP”. It seems the more appropriate  
> term would be “multiple inheritance” or am I missing something?

Okay. then this is a multiple inheritance problem??

---

<div class="post-metadata">

**Author:** ![martin\_gnu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/edb3f5/32.png) [@martin\_gnu](https://www.ruby-forum.com/u/martin_gnu)\
**Post date:** [April 25, 2008, 3:26am UTC](https://www.ruby-forum.com/t/inverse-oop/135708/6 "2008-04-25T03:26:18Z")

</div>

On 24 Apr 2008, at 22:45, Martin V. wrote:

> Okay. then this is a multiple inheritance problem??

I hate telling other people how to code, but yes it looks very much  
like a multiple inheritance problem.

Ellie

## Eleanor McHugh Games With Brains [http://slides.games-with-brains.net](http://slides.games-with-brains.net)

raise ArgumentError unless @reality.responds\_to? :reason

---

<div class="post-metadata">

**Author:** ![martin\_gnu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/edb3f5/32.png) [@martin\_gnu](https://www.ruby-forum.com/u/martin_gnu)\
**Post date:** [April 25, 2008, 3:23am UTC](https://www.ruby-forum.com/t/inverse-oop/135708/7 "2008-04-25T03:23:57Z")

</div>

On 24 Apr 2008, at 22:25, Robert K. wrote:

> What exactly do you mean by “intermediate”? Do you mean that all  
> projections should have the same interface? For that you do not  
> need inheritance at all - at least in Ruby. Or do you rather mean  
> that they share behavior (implementation)?
> 
> > > All map proyections have the same methods (geodetic\_to\_projected and  
> > > projected\_to\_geodetic)  
> > > Then define either a projection class from which they all inherit,  
> > > or a projection module which they all include.

And if these functions are included from a module their names should  
be to\_projected and to\_geodetic as it doesn’t matter to other classes  
what they’re being translated from.

> Nice reading from you again, Ellie. 🙂

Damn, I’ve gone and blown my anonymity again 😉

> I was going to also suggest the module approach. But I do wonder  
> why Martin chose to call it “inverse OOP”. It seems the more  
> appropriate term would be “multiple inheritance” or am I missing  
> something?

That was my reaction. I did a lot of similar work many years ago when  
I was a VB hacker and abstracted projections using interfaces, which  
are marginally similar to Ruby’s modules, but it’s possible Martin has  
some more complicated use case in mind.

Ellie

## Eleanor McHugh Games With Brains [http://slides.games-with-brains.net](http://slides.games-with-brains.net)

raise ArgumentError unless @reality.responds\_to? :reason

---

<div class="post-metadata">

**Author:** ![martin\_gnu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/edb3f5/32.png) [@martin\_gnu](https://www.ruby-forum.com/u/martin_gnu)\
**Post date:** [April 29, 2008, 12:16am UTC](https://www.ruby-forum.com/t/inverse-oop/135708/8 "2008-04-29T00:16:12Z")

</div>

Thanks all hehe

---

<div class="post-metadata">

**Author:** ![martin\_gnu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/edb3f5/32.png) [@martin\_gnu](https://www.ruby-forum.com/u/martin_gnu)\
**Post date:** [April 26, 2008, 2:46pm UTC](https://www.ruby-forum.com/t/inverse-oop/135708/9 "2008-04-26T14:46:03Z")

</div>

On 25.04.2008 03:25, Eleanor McHugh wrote:

> On 24 Apr 2008, at 22:45, Martin V. wrote:
> 
> > Okay. then this is a multiple inheritance problem??
> 
> I hate telling other people how to code, but yes it looks very much  
> like a multiple inheritance problem.

In fact, wasn’t that exactly what Martin mentioned in his first posting:  
a class that inherits from multiple parents? So basically MI is just  
the name for what he described in the first place.

Kind regards

robert
