[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

inverse OOP

Martin Vales

4/24/2008 9:40:00 AM

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.
--
Posted via http://www.ruby-....

9 Answers

Eleanor McHugh

4/24/2008 10:16:00 AM

0

On 24 Apr 2008, at 10:40, Martin Vales 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.??
>
> 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)

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-...
----
raise ArgumentError unless @reality.responds_to? :reason



Robert Klemme

4/24/2008 9:24:00 PM

0

On 24.04.2008 12:15, Eleanor McHugh wrote:
> On 24 Apr 2008, at 10:40, Martin Vales 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

Martin Vales

4/24/2008 9:45:00 PM

0

Robert Klemme wrote:
> On 24.04.2008 12:15, Eleanor McHugh wrote:
>> On 24 Apr 2008, at 10:40, Martin Vales 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.map...

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??


--
Posted via http://www.ruby-....

Florian Gilcher

4/24/2008 11:54:00 PM

0

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


On Apr 24, 2008, at 11:40 AM, Martin Vales 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 Gilcher
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)

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

Eleanor McHugh

4/25/2008 1:23:00 AM

0

On 24 Apr 2008, at 22:25, Robert Klemme wrote:
> On 24.04.2008 12:15, Eleanor McHugh wrote:
>> On 24 Apr 2008, at 10:40, Martin Vales 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.

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-...
----
raise ArgumentError unless @reality.responds_to? :reason



Eleanor McHugh

4/25/2008 1:26:00 AM

0

On 24 Apr 2008, at 22:45, Martin Vales 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-...
----
raise ArgumentError unless @reality.responds_to? :reason



Phlip

4/25/2008 7:46:00 AM

0

>> 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.??

Nobody said everything must inherit everything else.

> The core feature of OOP is composition.

The core feature of programming in general is composition by delegation.

The core feature of OO is, in Ruby parlance, the capacity for duck-typing.
Use it when you need it!


Robert Klemme

4/26/2008 12:43:00 PM

0

On 25.04.2008 03:25, Eleanor McHugh wrote:
> On 24 Apr 2008, at 22:45, Martin Vales 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

Martin Vales

4/28/2008 10:16:00 PM

0

Thanks all hehe
--
Posted via http://www.ruby-....