Windows Forms and Eiffel for .NET
Eiffel for .NET takes full advantage of the .NET platform. In particular, you can reuse the whole set of libraries provided via the .NET Framework. The next step is to build a graphical application using the Windows Forms library using Eiffel for .NET.
Building Graphical Applications with .NET Windows Forms
As a basis of comparison, Listing 2
shows a possible implementation of a simple Windows Form application written in C#.
This application is not fancy (see Figure 6) and illustrates only how to use the Windows Forms library.
|Figure 6: The "Hello World!" Windows form.|
EiffelStudio provides an Eiffel for .NET Base Class library, which follows the design principles found in the standard EiffelBase
. This library makes extensive use of contracts and genericity to provide a clean and powerful set of reusable data structures. The actual implementation of "EiffelBase.NET
" calls the Base Class library of the .NET Framework.
As for other .NET libraries, EiffelStudio provides a set of wrapper classes that enable you to reuse the corresponding types in your Eiffel for .NET applications. This is the case of the Windows Forms library.
Listing 3 shows how to develop the Windows Forms application just presented (see Listing 2) in Eiffel for .NET.
This code sample shows that class and feature names are the main differences between the C# and Eiffel for .NET versions. For example, the .NET class System.Windows.Forms.Form is called WINFORMS_FORM; System.Windows.Forms.Button is called WINFORMS_BUTTON, etc. Constructors are expressed by creation routines of the form "make_winforms_*", and property setters are replaced by "set" procedures (set_text, set_location, etc.).
Why such differences? The main reason is overloading: although part of the Common Language Specification of .NET, Eiffel does not support it. Hence, there will be name clashes for every overloaded feature that the Eiffel for .NET compiler needs to solve. The second reason is Eiffel naming convention: use of lower case and underscores rather than camel case. The Eiffel approach (and syntax) pursues the basic goal of software engineering: producing reliable software. It applies a fundamental rule of software construction: the principle of non-deception, stating that "differences in semantics should be reflected by differences in the text of the software." This rule is essential to improve the readability of the software text and minimize the risk of errors.
|Figure 7: The architecture of EiffelVision2, the portable Eiffel graphical library.|
Apart from such name mismatches, the use of Windows Forms is similar in Eiffel for .NET and C# (or any other .NET programming language).
Assembly dependenciesin this case, System.Windows.Forms.dll
are specified in your project settings that you can edit within EiffelStudio or Visual Studio .NET. (In C# or VB.NET, you would add the -r option to compile your project.)
Building Graphical Applications with the Eiffel Graphical Library
While having a set of class wrappers is nice, this is not always satisfactory. In the same way there is an EiffelBase for .NET with carefully expressed contracts, Eiffel for .NET also provides its own graphical library (EiffelVision2) on .NET. Listing 4 gives you an idea of what an EiffelVision2 application looks like.
The major advantage of using EiffelVision2 is platform portability. As a matter of fact, it is a fully portable library that offers an object-oriented framework for graphical user interface (GUI) development. It runs on Windows and all major versions of Unix (including Linux). It relies on a two-tiered architecture illustrated in Figure 7. WEL (Windows Eiffel Library) wraps the Windows API while GEL (GTK Eiffel Library) wraps the GTK APIs.
|Figure 8: EiffelVision application with a Windows Forms Datagrid displaying the content of a database through ADO.NET.|
Combining Graphical User Interfaces and Database Access with Eiffel for .NET
Particularly interesting is the ability to combine the EiffelVision2 mechanisms with the .NET facilities, such as Windows Forms. For example, you may want to display, in a possibly complex EiffelVision application, the contents of a database in a Windows Form Datagrid through ADO.NET. Figure 8
shows such a Datagrid, displayed as part of an EiffelVision window.
Web Services with Eiffel for .NET
The .NET Framework is built with the idea of Web services in mind: it provides the libraries needed to develop them (refer to the System.WebServices and System.Web.UI namespaces in the documentation). The next section describes building Web services in Eiffel for .NET.