[Next] [Previous] [Up] [Top] [Contents] [Index]

2.1 Objects and Inheritance

2.1.3 Extension Declarations

The inheritance structure of a named object may be augmented separately from the object declaration through an object extension declaration:

obj_ext_decl	::=	"extend" named_object {relation} [field_inits] ";"

In Cecil, object extension declarations, in conjunction with field and method declarations, enable programmers to extend previously-existing objects. This ability can be important when reusing and integrating groups of objects implemented by other programmers. For example, predefined objects such as int, i_vector, and m_vector are given additional behavior and ancestry through separate user code. Similarly, particular applications may need to add application-specific behavior to objects defined as part of other applications. For example, a text-processing application may add specialized tab-to-space conversion behavior to strings and other collections of characters defined in the standard library. Other object-oriented languages such as C++ [Stroustrup 86, Ellis & Stroustrup 90] and Eiffel do not allow programmers to add behavior to existing classes without modifying the source code of the existing classes, and completely disallow adding behavior to built-in classes like strings. Sather is a notable exception, allowing a new class to be defined which is a superclass of some existing classes [Omohundro 93]. Section 3.3.3 explains how object extensions are particularly useful to declare that two objects, provided by two independent vendors, are subtypes of some third abstract type. Section 5 describes how modules can be used to localize extensions to particular regions of code.