Cook Computing

Using Eiffel Classes in .NET

September 30, 2002 Written by Charles Cook

Eiffel classes are grouped in clusters. These seem to roughly correspond to .NET assemblies. To enable the classes in a project to be packaged in an assembly for use from other .NET languages a cluster namespace is defined in the project properties. The classes in the assembly then belong to this namespace.

The contents of an assembly is more complicated than you would initially expect. Because of the difference in object models between Eiffel and the CLR, for each Eiffel class there are two classes and an interface in the generated assembly. For example if you implement an Eiffel class called Quux, the assembly contains an interface called Quux and classes Create.Quux and Impl.Quux.

The interface is the type by which the Eiffel class is referred to, for example when defining a variable to refer to an instance of the class or defining a method parameter:


Quux quux;
void UseQuux(Quux q) { /* ... */ }

Creation of a class instance in Eiffel involves creating an instance of the class and then initializing it via a creation procedure. There can be more than one creation procedure for a class and they do not have special names. Therefore it is not possible to generate overloaded constructors as in the CLR. To handle this the Create class generated in the assembly contains a static method for each of the creation procedures. For example if the Eiffel class Quux contains a creation procedure called make it would be called like this in C#:


Quux quux = Create.Quux.Make();

The second class Impl.Quux is, as the name suggests, the implementation of Quux. This is the type that is actually instantiated by the Create method. It also is the type to derive from, for example:


class ChildQuux : Impl.Quux
{
// ...
}