Re: [R] inheritence in S4

From: Martin Morgan <mtmorgan_at_fhcrc.org>
Date: Mon, 24 Mar 2008 11:00:58 -0700

cgenolin_at_u-paris10.fr wrote:

>> callGeneric is an advanced topic.

>
> Ok, when I will be older :-)
>
>>> *************************
>>> This works :
>>>
>>> setMethod("initialize","B",
>>>          function(.Object,..., yValue){
>>>              callNextMethod(.Object, ..., y=yValue)
>>>              return(.Object)
>>>          })
>>> new("B",yValue=3)
>>>
>>> but this does not :
>>>
>>> setMethod("initialize","B",
>>>          function(.Object, yValue){
>>>              callNextMethod(.Object, y=yValue)
>>>              return(.Object)
>>>          })
>>> new("B",yValue=3)
>>>
>>> Why ?
>>> Is there any help page about ... ?
>>
>> Both 'work' in the sense that an object is returned

>
> Well yes, but the second one does return an object without assigning the
> value 3, that is not realy working...

I wasn't paying enough attention to your code. callNextMethod is like any R function -- it will not change .Object 'in place', but makes a copy, modifies the copy, and returns the copy. So either

setMethod("initialize","B",

          function(.Object,..., yValue){
              .Object <- callNextMethod(.Object, ..., y=yValue)
              return(.Object)
          })

or more compactly

setMethod("initialize","B",

          function(.Object,..., yValue){
              callNextMethod(.Object, ..., y=yValue)
          })

The code example is incomplete, so I don't really know why one version assigned y=3 for you and the other did not; for me, neither version did the assignment.

Martin

>> In an object-oriented sense, initialize,B-method should really just 
>> deal with it's own slots; it shouldn't have to 'know' about either 
>> classes that it extends (A) or classes that extend it. And it 
>> shouldn't do work that inherited methods (i.e., initialize,ANY-method) 
>> do.

>
> I get your point and I agree : I am developing B, you are developing A,
> I do not want to know what is in A so B should not initialize its 'A part'
>
> On the other hand, I do not like the "..." . "..." can be anything,
> there is no controle at all, no type checking.
> I would prefers to initialize B giving its value for its own slot AND an
> object class A. So I send you the value for A, you send me an objets
> 'aaa' of class A then I initialize B with some value and aaa. This way,
> B keep its role but does not transmit anythink to A without controling it.
>
> Best,
>
> Christophe
>
> ----------------------------------------------------------------
> Ce message a ete envoye par IMP, grace a l'Universite Paris 10 Nanterre
>
>
>
-- 
Martin Morgan
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M2 B169
Phone: (206) 667-2793

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 24 Mar 2008 - 18:05:27 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 24 Mar 2008 - 19:31:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive