[ | smalltalk dot org ].
Community and industry meet inventing the future.

Extending Encapsulation For Smalltalk
written by Peter William Lount
version 1, 20041207 5:36 pm PST
version 2, 20041208 1:39 am PST, added link to pdf paper.

In their OOSPLA presented paper, "Object-Oriented Encapsulation for Dynamically Typed Languages", Nathanael Schärli, Andrew P. Black and Stéphane Ducasse write:
"Encapsulation in object-oriented languages has traditionally been based on static type systems. As a consequence, dynamically-typed languages have only limited support for encapsulation. This is surprising, considering that encapsulation is one of the most fundamental and important concepts behind object-oriented programming and that it is essential for writing programs that are maintainable and reliable, and that remain robust as they evolve."
The abstract for their paper continues with:
"In this paper we describe the problems that are caused by insufficient encapsulation mechanisms and then present object-oriented encapsulation, a simple and uniform approach that solves these problems by bringing state of the art encapsulation features to dynamically typed languages. We provide a detailed discussion of our design rationales and compare them and their consequences to the encapsulation approaches used for statically typed languages. We also describe an implementation of object-oriented encapsulation in Smalltalk. Benchmarks of this implementation show that extensive use of object-oriented encapsulation results in a slowdown of less than 15 percent."

The language that they provide their implementation in is a modified Squeak Smalltalk system. It seems impressive that they could implement their ideas very rapidly and have it only cost 15%. Further work that tighly integrates this extension into virtual machines would likely have opportunities for improvement.

In addition I recommend reading the groups earlier paper, "Composable Encapsulation Policies" (authored by Nathanael Schärli, Stéphane Ducasse, Oscar Nierstrasz, and Roel Wuyts) which opens by saying:
Given the importance of encapsulation to object-oriented programming, it is surprising to note that mainstream object-oriented languages offer only limited and fixed ways of encapsulating methods. Typically one may only address two categories of clients, users and heirs, and one must bind visibility and access rights at an early stage. This can lead to inflexible and fragile code as well as clumsy workarounds. We propose a simple and general solution to this problem in which encapsulation policies can be specified separately from implementations. As such they become composable entities that can be reused by different classes. We present a detailed analysis of the problem with encapsulation and visibility mechanisms in mainstream OO languages, we introduce our approach in terms of a simple model, and we evaluate how our approach compares with existing approaches. We also assess the impact of incorporating encapsulation policies into Smalltalk.

In addition to becoming "composable entities that can be reused by different classes" the "encapsulation entities" become first class "meta-data" objects in the system. This is an extremely important aspect of Smalltalk influenced systems that can't be over stated too much. Any language feature added to Smalltalk influenced systems that doesn't provide first class meta data objects for those features needs to be rethought if it's going to pass muster. A major problem with langauges like PERL, C++, C#, Java, JavaScript, etc... is that they don't provide the meta data objects for much of the features of their langauges, thus the programmers and the "environments" that they build are limited from the start. Put another way languages that have limited meta data to a subset of what is possible are only giving you part of the power possible. Why not go for all the power and use a language that provides full meta data access to all of the language features?

Part of what makes having language accessible meta data accessible using in the language itself (rather than some other syntax) is unity and simplicity of using the meta data. Smalltalk influenced languages treat their meta data as full first class objects. This means that you can for example, iterate over all the classes in the system performing whatever actions you need at run time. This enables the "environment" to provde tools for programmers and users alike that wouldn't be possible or easily done in languages that don't have "class" meta data. The key to the success of this is that the meta data are first class objects treated like all the others! All extensions to Smalltalk that include new forms of meta data must have this "first class meta data object" characteristic to fully be integrated into the language.

The "encapsulation" technology presented in these papers provide dynamic languages with a path forward opening new possibilities and capabilities while retaining the essential core characteristics that are essental for their success. This research is grounded in reality with an actual implementation.

These papers are one of the nice suprises from the OOPSLA 2004 conference! They also provide further evidence that Smalltalk is evolving to meet the needs of the information systems marketplace.


Copyright 1999-2010 by Smalltalk.org"!, All Rights Reserved.