[R] Call super methods from inherited classes R.oo

batnix adam.lukaszewski at gmail.com
Thu Aug 18 14:20:58 CEST 2011


Hi R-community,

I'm very busy with a software project which I would like to development
completely with R.oo. Many of the object oriented aspects that I already
know from Java development seems to be in place with this library.
But...there is something that I'm really missing... *the super method call*

Just a little example that shall demonstrate what I mean: 
Image we have the following class hierachie that I graped from another post
- thx to YuriWerewolf ;-).

*ClassA*
setConstructorS3("ClassA", function(A) {
  extend(Object(), "ClassA",
    .size = A
  );
})

setMethodS3("print", "ClassA", function(this,...) {
  print(paste('Class A:',this$.size));
})

*ClassB (inherits ClassA)*
setConstructorS3("ClassB", function(B=15) {
  extend(ClassA(), "ClassB",
    .something = B
  );
})

# Now I would like to extend the behavior of the super$print() method. It is
not intended to
# get rid of the super$mehtods logic but to execute it too and add some more
specific commands.
setMethodS3("print", "ClassB", function(this,...) {
  /super$print()/ # this kind of call is missing
  print(paste('Class B:',this$.something));
}) 

Hopefully I could make clear what I mean.

Thanks and best regards,
Adam L.


--
View this message in context: http://r.789695.n4.nabble.com/Call-super-methods-from-inherited-classes-R-oo-tp3752441p3752441.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list