University of Sheffield Reusable Pieces of High-Level Design   

    ReMoDeL - Reusable Model
    Design Languages


OOP Example: the Greeter Program

Introduction

The following is a simple example of a ReMoDeL OOP model, and its translation into different programming languages. The contents of the model are provided in an XML file, which follows the approved encoding for ReMoDeL OOP. The translations were carried out by ReMoDeL code generators.

The Greeter Program

Click the link below to load the example OOP model into your browser. The model is a plain XML file, with no attached stylesheet, so it should display as a tree. Use the plus and minus signs in the margin to expand or collapse parts of the model.

The root element is a Package which declares that it defines an OOP model. All ReMoDeL models are defined in packages, which declare which model they contain. Packages are often named and specify a location; but this one is unnamed and has no location. As a result, generated code will belong to the default package (the top-level namespace) and will be placed in the current working directory. The package contains the definition of a single class, named Greeter.

Various features of ReMoDeL OOP are illustrated in this example, including:

The Java Translation

Click the link below to load the generated Java source code for the Greeter class. This file would be placed in the top-level working directory, since the package specified no location.

Whereas the Java source file has no Java package declaration, suitable import statements have been inserted to refer to classes from other packages. In particular, the default root Object from lib.core is required; and two classes StandardReader and StandardWriter from the package lib.io are required. Systems generated from ReMoDeL OOP must interface with standard libraries in each target language; this may require creation of special-purpose libraries. At translation-time, the translator specified that Greeter was the system entry point; as a consequence, a main() method was also generated in Java.

Various features of the Java translation are illustrated in this example, including:

In principle, this class may be executed directly as a system, on any Java compiler (assuming the library classes exist).

The C++ Translation

Click the links below to load the generated C++ source code for each of the files generated for the Greeter program. These files would be placed in the top-level working directory, since the package specified no location.

For C++, two files are generated for each class: a header file, and a source file. In addition, if the class is specified at translation-time as the entry-point for the system, then a separate source file is created for the main() program (a collection of C++ classes may only contain one main program). Dependency upon other types is covered by #include directives, where the type must be fully processed, and forward declarations, where only pointers are used. A smart pointer implementation is used to store references to dynamically-created objects. This supports reference-counted garbage collection, provided in a special-purpose core library.

Various features of the C++ translation are illustrated in this example, including:

In principle, this class may be executed directly as a system, on any C++ compiler (assuming the library classes exist).




Created for the ReMoDeL Project on Friday October 16 17:20:15 2009; © Anthony J H Simons.