Wolfgang De Meuter
Last revision: August 7th, 1996

Encapsulation in Agora


Since Agora is solely based on message passing (in fact the entire Agora interpreter can be regarded as a message passing engine), Agora objects are strongly encapsulated. But even within these limits, we were able to include features like inheritance, cloning and reflection.

Inheritance with mixin-methods

The fact that objects in Agora only implement message passing and no delegation at first sight seems to preclude inheritance. However, by providing an object with a number of special methods, called mixin-methods, it is still possible to have inheritance. The idea is that a mixin-method is a method that lists a number of extra attributes that will be added to the object upon invokation of the mixin-method. This can result in a functional extension of the object (i.e. a view) or in an imperative extension of the object (imperative mixin-methods were implemented in Agora96 and in Agora98 - Note that they are called 'mixins' in Agora98).
So the general idea of mixin-methods is that, although objects can only be sent messages to, objects are perfectly capable of extending themselves upon receiving a message. To accomplish this, the implementation of a mixin-method takes the internal structures of an object and adds the required attributes. In no way, these internal structures can be seen or filled in by other objects.

Cloning with cloning methods

Providing a cloning operator on objects (i.e. adding a clone method to the MOP) isn't really necessary in order to clone objects. Although Agora-S and Agora94 implement an explicit cloning operator (i.e. they allow an object to be cloned 'from the outside'), Agora96 and Agora98 do not. The idea is that one must send a message to a prototype to clone it. If the message is implemented by a cloning method, the cloning method will make a copy of the internal structures of the receiving object, and will execute it's body in the context of the cloned object. Cloning methods may be a solution to the prototype corruption problem.

Reflection doesn't breach encapsulation

Often, a MOP allows meta-level programs to see much more of an object than ordinary base level programs. In Agora this is not so. Because of the simplicity of the Agora MOP (it only knows send), a meta-level program can never breach the encapsulation of an object, that is, it is impossible to bypass the interface of an object by going meta.