Browse DevX
Sign up for e-mail newsletters from DevX


Eiffel for .NET: An Introduction : Page 3

Eiffel Software Inc.'s Eiffel for .NET is now available as part of ESI's EiffelStudio. Eiffel for .NET combines the power of two object technology variants: Eiffel (including Design by Contract, multiple inheritance, genericity and seamlessness of software development) and .NET (including language interoperability, Web services and other advanced facilities).




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Full Interoperability with Other .NET Languages
Now that you understand the scope of Eiffel for .NET and how it interoperates with the .NET Framework, let's continue with a Hello World example and how to reuse an Eiffel for .NET component from two other languages: C# and Visual Basic .NET.

A Hello World Example with Eiffel for .NET
Listing 1 gives a possible implementation of a Hello World sample using Eiffel for .NET.

Compiling the sample produces a .NET assembly that is language independent. This assembly can be reused from any .NET language without knowing it was programmed in Eiffel for .NET.

Reusing an Eiffel for .NET Component from C# and VB.NET
Reusing an Eiffel for .NET component from C# (or VB.NET) is almost transparent to the software developer.

As a client, the only difference is in the instantiation of a type originally written in Eiffel for .NET: the programmer has to use the generated Create class mentioned before.

The sample below reuses the Eiffel for .NET component generated from the Hello World sample presented earlier (see Listing 1) as a client:

public class HelloWorld1 { public static void Main() { HelloWorld sample; sample = Create.HelloWorld.Make(); } }

In Listing 1, the class is called HELLO_WORLD whereas the class name used in the sample above is Create.HelloWorld. How can it be? You can set the option "dotnet_naming_convention" in the project settings file (the ACE file) to force the Eiffel for .NET compiler to generate .NET-friendly names. This option is disabled by default. However, if that feature is enabled, class and feature names are changed using the following conventions: my_feature becomes MyFeature and MY_CLASS becomes MyClass. Therefore, in our example, HELLO_WORLD has been changed to HelloWorld.

Once class HelloWorld has been instantiated, the C# programmer can use the object (sample in the above code) like any other C# object, transparently from its original Eiffel for .NET implementation.

Here is the VB.NET counterpart of the example:

Public Class HelloWorld1 Public Sub Main() Dim sample as HelloWorld sample = Create.HelloWorld.Make() End Sub End Class

As an heir, the C# class has to know about the generated Impl class (since the original class name refers to an interface). With this exception, inheriting from an Eiffel for .NET class is the same as inheriting from a C# class: all exported features are available to the descendant.

The following code reuses the Hello World sample shown in Listing 1 as a descendant: it inherits from the generated class Impl.HelloWorld and uses the method HelloWorldMessage originally defined in the Eiffel for .NET class as the String constant Hello_world_message.

using System; public class HelloWorld2:Impl.HelloWorld { public static void Main() { HelloWorld2 h2; h2 = new HelloWorld2(); Console.WriteLine (h2.HelloWorldMessage()); } }

Here is the same example written in VB.NET:

Imports System Public Class HelloWorld2 Inherits Impl.HelloWorld Public Shared Sub Main() Dim h2 as HelloWorld2 h2 = new HelloWorld2() Console.WriteLine (h2.HelloWorldMessage()) End Sub End Class

Integration in Visual Studio .NET
Eiffel for .NET is a released product and is available as part of the ESI's EiffelStudio 5.1. The forthcoming release of ESI's EiffelStudio 5.2, will provide major improvements in the areas of speed, efficiency and reliability.

In September 2002, ESI will release Eiffel ENViSioN! 1.0, a stand-alone plug-in for Visual Studio .NET. Eiffel ENViSioN! represents a major accomplishment in porting Eiffel to the .NET Framework, allowing developers to use the Eiffel method and language seamlessly within Microsoft's Visual Studio .NET. Eiffel programmers will appreciate the cross-language browsing and debugging facilities of Visual Studio .NET while VS.NET users will take advantage of Eiffel mechanisms such as the smart editor (with automatic completion of class and feature names) and project cluster browsing facilities of EiffelStudio.

Providing full interoperability with the other .NET programming languages gives Eiffel developers the opportunity of using two complementary development environments; EiffelStudio and Visual Studio .NET.

With Eiffel ENViSioN!, Eiffel for .NET users have the possibility to always select the programming environment that is best suited for their project:

  • EiffelStudio for full-Eiffel development (see Figure 1).
  • Visual Studio .NET for multi-language development (see Figure 4).
Figure 4 shows a multi-language project developed under Visual Studio .NET; it involves three .NET programming languages: C#, Visual Basic .NET and Eiffel.

Figure 4: A multi-language project with Visual Studio .NET.
As mentioned before, one key feature of Visual Studio .NET is its support for cross-language debugging. Figure 5 illustrates a debugging session under VS.NET for an Eiffel project. You can see:

  • The place in a routine text where the execution is currently stopped (top-left pane).
  • The browsing facilities, using the same conventions as within EiffelStudio (top-right pane).
  • The local variables, with their declaring types and values (bottom-left pane). This panel also lets you define "watch lists" and evaluate expressions on the fly.
  • The compiler output (bottom-right pane).
Figure 5: A debugging session under Visual Studio .NET.
These examples reveal the complementary nature of the two development environments that Eiffel for .NET users have at their disposal. Thus, having the choice between them is a major advantage.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date