comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Need advice about inheritance
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Need advice about inheritance [message #44365 is a reply to message #44303] Fri, 10 June 2005 02:21 Go to previous messageGo to previous message
Antonio Santiago is currently offline  Antonio Santiago
Messages: 201
Registered: February 2004
Senior Member
Like Marc I think the best solution is to override the add method. As he
says you can use the template pattern, that is, put the common code into
an auxiliar method.

Anyway, I think it is more a concept problem. Supose the class PERSON
and subclasses MAN and WOMAN. It is a bit strange to call:

man = some_person->set_address(xxx)

it must be

person = some_person->set_addres(xxx)

Perhaps this example isn't the best, but applied on your case (and in my
own opinion) is a bit strange to add two datas and obtain a time_data.
That is if you add two integers is a bit strange get a float as result
(possible but strange). You can is something like a cast after an operation.

I don't know how you model the problem, I supose something like:

DATA <----- TIMEDATA

Note that a TIEMDATA object also is a DATA object, but a DATA object
maybe isn't a TIMEDATA object. A method on TIMEDATA can return a
reference to TIMEDATA object, that in fact is a DATA object, but is
dangerous (i think so) to execute a method on DATA and return a TIMEDATA
object.

Leaving theory on a side (but remember we must follow it), why not
implement a "clone" method in both classes and:

FUNCTION Data::Add, some_data_or_timedata_object

new_object = some_data_or_timedata_object->Clone()

self->GetProperty, MONTH=m1, DAY=d1, YEAR=y1
new_object->GetProperty, MONTH=m2, DAY=d2, YEAR=y2

new_object->SetProperty, MONTH=m1+m2, DAY=d1+d2, YEAR=y1+y2

RETURN, new_object
END

In this case, you can pass to Data::Add any DATA or TIMEDATA oboject and
you return the same type of object. The pproblem becomes with TIMEDATA
class. Has it got an Add method? If yes, which type of object you can
pass DATA or TIMEDATA. Depends of its types TIMEDATA::Add method must
work different (getting the properties of TIMEDATA plus theb month, day
and year).



If you can model your problem first (UML) and all is ok, the only
(sometimes not :) ) final task is to imlpement it.


I hope this crazy email will be useful for you, bye :)

--
-----------------------------------------------------
Antonio Santiago P�rez
( email: santiago<<at>>grahi.upc.edu )
( www: http://www.grahi.upc.edu/santiago )
( www: http://asantiago.blogsite.org )
-----------------------------------------------------
GRAHI - Grup de Recerca Aplicada en Hidrometeorologia
Universitat Polit�cnica de Catalunya
-----------------------------------------------------
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: array of pointers inside a structure
Next Topic: Re: mosaic two images in direct graphics

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Thu Oct 09 18:59:21 PDT 2025

Total time taken to generate the page: 0.24249 seconds