Subject: Encapsulation

From: [email-masked] (Gustavo Glusman)
Date: Sat, 20 Nov 1993 09:38:48 -0800

I had an idea for a change to the MOO basic functioning, that would allow
for a relatively easy implementation of one aspect of object-orientedness
that MOO lacks - encapsulation.
Being a biologist, I have only a vague idea of what encapsulation really
implies...
...but I understand that, in a system with encapsulation, objects control
the information they store (properties, in our case), so that other objects
can't freely read it, or write on it.
Where MOO stands now, object A can just use B.propname to get that info,
and if the expression B.propname is at the left side of a "=", it just
writes into it. (all this, controlled by permissions, OK, but this is not
the main point now)
If encapsulation was there, A would have to 'send a message' to B asking
for the value in 'propname', or telling B to assign a new value to
'propname'.
In fact, 'propname' could even just be undefined on B. From A's point of
view, what B does is irrelevant, as long as it gives the requested
info/accepts the given info.

After all this... my proposal:

(1) Whenever the server finds a reference (in a verb on object A) to a
'property' defined on 'this' (A), it treats it as usual. (an object
accesses its info naturally)
(2) Whenever the server finds a reference (in a verb on object A) to a
'property' defined on another object (B), it checks for the presence of a
callable verb with the same name as the 'property'.
    (2a) If there isn't such a verb, the treatment is as in (1).
    (2b) If there is such a verb, it is called, and its return value is the
value of the 'property'.
(3) If the reference to the property is on the left side of a "=", the verb
is called with one parameter: the value to assign to the property. In all
other cases (that is, when the property information is being retrieved) the
verb is called without parameters.

Examples:

For verbs defined on object #A, assuming (this != player), just for the example:

The code you write           What it does in fact
...
foo1 = this.bar;       \
foo2 = #A.baz;            No changes... the object is using
this.bar = foo2;          internal information.
#A.baz = foo1;         /
...

...
foo1 = player.bar;    ==>   foo1 = player:bar();
foo2 = #B.baz;        ==>   foo2 = #B:baz();
player.bar = foo2;    ==>   player:bar(foo2);
#B.baz = foo1;        ==>   #B:baz(foo1);
...

The :propname verb would default to:

if (args)
  this.(verb) = args[1];
else
  return this.(verb);
endif

As you can see, now any object/object-class can control access to its
internal information.
It simply has to define a verb named accordingly.
In fact, an object now can 'provide' answers for properties it doesn't even
define. As stated above, when A asks B for the value of some property, it
needn't be concerned about whether B really defines it.
If B has a suitable verb...

I think most of the existing MOOcode wouldn't crash with such a change, but
I haven't probed too deeply.
In fact, no little work has already been done in this direction. Examples
are use of :description, :all_sorts_of_msg, etc.

How difficult would it be to implement this?
Do people think it would be useful?
Would it break existing code too badly? Would such a change mean server 2.1.1?

---

From: Pavel Curtis <[email-masked]>
Date: Sat, 20 Nov 1993 12:31:44 -0800

> Date:	Sat, 20 Nov 1993 09:38:48 -0800
> From:	[email-masked] (Gustavo Glusman)
> 

I think you're wrong here.

> How difficult would it be to implement this?

It would be more-or-less straightforward to implement this.

> Do people think it would be useful?

I might agree that it was a good idea, if I were working from a clean slate; as
I am not doing so, I think it's too wildly incompatible for consideration.

> Would it break existing code too badly?

I believe so.

	Pavel