From maiagx at gmail.com  Mon Nov 23 11:04:04 2009
From: maiagx at gmail.com (Charlotte Maia)
Date: Mon, 23 Nov 2009 23:04:04 +1300
Subject: [Rd] OOP with Encapsulated Class Definitions
Message-ID: <b7bfe54e0911230204t68a846cft25e008f69b9e31a3@mail.gmail.com>

Hi all,

I'm seeking feedback (good, bad or indifferent) in regards to
developing (further) a new class system for R, that uses encapsulated
class definitions (i.e. the method definitions are literally inside
the body of the class definition).

A working (however very rough and poorly tested) system is available
in my R package "oosp" with documentation in the vignette
"oosp2_Encapsulated_Classes_in_R".

A snippet of a class definition follows:
(Here double is a method that doubles the value of the attribute x).

> MyObject = function (...)
{   MyObject = function (x) .$x = x
    double = function () .$x = .$x * 2
    mclass ()
}

A snippet of creating and using an object:

> myobject = MyObject (10)
> myobject$x
[1] 10
> myobject~double ()
> myobject$x
[1] 20

Here class definitions are functions, however there are other possibilities...
Priority has been given to space rather than speed, hence the
unorthodox method despatch, however again, there are other
possibilities...

Here is an example of inheritance:

> MySuperClass = function (...)
{   MySuperClass = function (x) .$x = x
    mymethod = function () cat (.$x, "\n")
    mclass ()
}

> MySubClass = function (...)
{   MySubClass = function (y) super (y)
    mclass (super="MySuperClass")
}

> myobj = MySubClass (10)
> myobj~mymethod ()
10


kind regards
Charlotte Maia
(first time poster)



[Rd] OOP with Encapsulated Class Definitions
Charlotte Maia