The Fragile Object Problem (Part 1)
It’s assumed that languages like Self, which lack classes by design, can not suffer from [supposedly] class related issues. Some of these issues have little to do with classes and so should be considered.
The effect of strong coupling between classes and their ancestors is referred to as “The Fragile Base-class Problem”. As you may expect, systems that suffer from this problem tend to be very sensitive to change.
This problem in particular is quoted as being an inherent benefit of classless object-oriented languages, but has nothing to do with classes and everything to do with inheritance.
Delegation, as found in almost all of these languages is a form of dynamic inheritance. It allows the parent (or parents) of an object to be changed as the program is executed.
On a side-note, even though this method of inheritance is often referred to as prototype-based inheritance it can also be used with classes.
While delegation has many advantages over static inheritance, the problem persists. It does so because delegation follows the same basic principles as standard inheritance. There are no classes but objects are still arranged hierarchically.
Consequently, changes made to one object automatically effect other objects.
This is where classless languages get a chance to shine. Due to the ease of refactoring in these languages, the effect of unwanted coupling like this can be dramatically reduced. At a cost.
At this point it’s worth considering why we organize programs into hierarchies to begin with. There are many good reasons for doing this. If I were to pick just two they would probably have to be: management of complexity and propagation of change.
When objects are placed into a hierarchy we can assume some interesting properties about them.
One of these being that objects in a hierarchy will exhibit all of the behaviors of those located above them. This allows us to reuse knowledge we already have about an object when trying to understand another.
Standard inheritance and delegation provide a convenient way of propagating changes.
The true nature of inheritance may be the subject of academic dispute, but for the purpose of this article I’ll consider inheritance as the mechanism by which one object derives its behavior from another in a given instant.
Both of these are highly desirably qualities for a system of inheritance to have, but they’re not without their disadvantages.
Since the description of an object is spread out above it, the former makes it harder to understand an object individually. You need to understand each object above the one you’re interested in!
The latter introduces a wondrously strange dependancy between an object and its ancestors. Any changes made to an object, no matter how small, will alter all of its descendants.
I feel that it’s a combination of these two qualities which leads to what I would like to (more appropriately) call “The Fragile Object Problem”.
Part two will continue along the same lines as part one. In particular I hope to present how the problem is being addressed in the design of Hula, a new classless object-oriented programming language.
If you have any comments, corrections or contributions please feel free to shout.
0 comments:
Post a Comment