2.2.2. The concept of Interface

Before describing in detail the MeshViz Interface features, it is important to understand the concept of interface used to define the mesh data structures. This is a key concept in MeshViz Interface which must be understood before going any further. This concept provides a simple and convenient way to delegate the definition of the mesh to the application so that MeshViz Interface can adapt to any kind of mesh data structure.

All interface class names start with the Mi prefix


An interface is a C++ class similar to an interface in the Java™ language. However, as this is not a concept of the C++ language, we will describe below the particular properties of what we call an interface:

  • An interface does not contain any member variables, neither public, protected nor private.

  • An interface does not contain any non virtual methods except template methods

  • Most virtual methods do not have any implementation, thus are "pure" virtual

  • An interface can't be instantiated, thus derived classes must be built by user applications. Only a reference or pointer to an interface can be declared.

Default implementations of methods

Some methods have a default implementation in order to avoid a tedious derivation. Two types of default implementation exist:

  • An implementation throwing an exception. This type of implementation is used for methods that are called only in some particular cases. For instance, the MiCell::isPointInside() method is used only when doing probing. As long as probing is not used by the application, It is not necessary to override isPointInside(). However, if the default method throws an exception, it means that the method must be implemented and the application must provide its own implementation.

  • The default behavior is the most general case or a natural and obvious implementation of the method exists. For instance the MiTopology interface provides a default implementation for hasDeadCells() which returns false indicating that there is no dead cells in the topology. Some convenience methods such as toStream and operator << are also provided for writing a mesh to a stream.

Multiple inheritance

The concept of interface is often used with multiple inheritance. For instance if the application contains an existing class AppCell defining a cell, this class can be derived to implement the MiCell MiCell interface. In this case, the new class AppMiCell inherits both from MiCell MiCell and AppCell like in the following graph:

Multiple inheritance example

Figure 2.1. Multiple inheritance example

In this example, the AppMiCell class implements the pure virtual method getNumNodes() by returning the inherited protected member numNodes of AppCell. The user application passes a pointer or a reference to this new AppMiCell class to the MeshViz extraction module.

Thanks to the particular properties described above, the multiple C++ inheritance used here does not introduce any multiple member inheritance as can happen when using classical multiple inheritance. Moreover, the new class AppMiCell usually does not need additional members.

Note for C++ experts:

In some cases the inheritance of the interface must be declared as virtual:

class AppMiCell: virtual public MiCell, public AppCell




The inherited interface must be first in the list of inherited class

Note for Java experts:

An interface class in MeshViz Interface corresponds to a Java abstract class without member.