[Rd] Reference classes: opinion on OOP design

From: Janko Thyson <janko.thyson_at_ku-eichstaett.de>
Date: Wed, 17 Nov 2010 19:55:43 +0100


Dear list,

I'm aware that this post does not really comply with the posting guide with respect to "providing a minimal reproducible code example". But I do hope it's okay that I spared uninterested readers by putting that into the attachment ;-)

The thing is that I'm not really familiar with "true" OOP as R is my first programming language. So I wanted to ask kindly for some expert opinion on a certain paradigm I've come up with concerning my use of class defs and methods (S4 Reference Classes and S4 methods).

MY GOAL:
I thought it'd be neat to have Reference Class instances that can
- load data from remote places (e.g. a db, file whatever) on demand

The instances should be flexible enough to work in an "static only" and "dynamic only" context and should make as much use of existing functionality (e.g. S4 classes, S4 method dispatch etc.) as possible. I do want to have the choice if I'm carrying (possibly loads of) data with me in the fields of my object or if I compute/get them based on some function whenever I actually need it. For example, I'm thinking about parameter estimates that could automatically be reestimated based on rules that take into account a constantly changing data structure (new observations come it quite frequently or something like that).  

What do you think of the way I've implemented this? Does this make sense to you or is something like this done in another (and probably more elegant ;-)) way?

THE HOMEWORK I DID
- I've looked at active bindings which are nice. But this limits me to funs
with either none or one argument if I'm not mistaken.
- I do like the idea of 'getRefClass("Blabla")$accessors(.)' setting up
get/set methods for me, but would need to customize them to my specific needs
  (e.g. handling the default values of method arguments etc.)

I've attached a code example and would really appreciate your comments if you find some time.

Thanks a lot!!
Janko



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 17 Nov 2010 - 18:57:40 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 Wed 17 Nov 2010 - 20:00:23 GMT.

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

list of date sections of archive