Prev Up
Go backward to 3.2.1 The Syntax of Object-Oriented Modules
Go up to 3.2 Object-Oriented Modules

3.2.2 Transforming Object-Oriented Modules into System Modules

The best way to understand classes and class inheritance in Maude is by making explicit the full structure of an object-oriented module, which is left somewhat implicit in the syntactic conventions adopted for them. Indeed, although Maude's object-oriented modules provide convenient syntax for programming object-oriented systems, their semantics can be reduced to that of system modules. We can regard the special syntax reserved for object-oriented modules as syntactic sugar. In fact, each object-oriented module can be translated into a corresponding system module whose semantics is by definition that of the original object-oriented module.

However, although Maude's object-oriented modules can in this way be reduced to system modules, there are of course important conceptual advantages provided by the syntax of object-oriented modules, because it allows the user to think and express his or her thoughts in object-oriented terms whenever such a viewpoint seems best suited for the problem at hand. Those conceptual advantages would be lost if only system modules were provided.

In the translation process, the most basic structure shared by all object-oriented modules is made explicit by the CONFIGURATION functional module defined at the beginning of this section. The translation of a given object-oriented module extends this structure with the classes, messages and rules introduced by the module. For example, the following system module is the translation of the ACCNT module introduced earlier. Note that a subsort Accnt of Cid is introduced. The purpose of this subsort is to range over the class identifiers of the subclasses of Accnt. For the moment, no such subclasses have been introduced; therefore, at present the only constant of sort Accnt is the class identifier Accnt.

  mod ACCNT is 
        including MACHINE-INT . 
        including QID . 
        including CONFIGURATION .
        sorts Accnt . 
        subsort Qid < Oid . 
        subsort Accnt < Cid . 
        op Accnt : -> Accnt . 
        op credit : Oid MachineInt -> Msg . 
        op debit : Oid MachineInt -> Msg . 
        op transfer_from_to_ : MachineInt Oid Oid -> Msg . 
        op bal :_ : MachineInt -> Attribute . 
        var A : Oid . 
        var B : Oid . 
        var M : MachineInt . 
        var N : MachineInt . 
        var N' : MachineInt . 
        var V@Accnt : Accnt . 
        var ATTS@0 : AttributeSet . 
        var V@Accnt1 : Accnt . 
        var ATTS@2 : AttributeSet . 
        rl [credit] : credit(A, M) 
                < A : V@Accnt | bal : N, none, ATTS@0 > 
          => < A : V@Accnt | bal : (N + M), ATTS@0 > . 
        crl [debit] : debit(A, M)
                < A : V@Accnt | bal : N, none, ATTS@0 > 
          => < A : V@Accnt | bal : (N - M), ATTS@0 > 
             if N > M = true . 
        crl [transfer] : (transfer M from A to B) 
                < A : V@Accnt | bal : N, none, ATTS@0 > 
                < B : V@Accnt1 | bal : N', none, ATTS@2 > 
          => < A : V@Accnt | bal : (N - M), ATTS@0 > 
             < B : V@Accnt1 | bal : (N' + M), ATTS@2 > 
             if N > M = true . 
  endm

We can describe the desired transformation from an object-oriented module to a system module as follows30:

The rewrite rules given in the original ACCNT module are interpreted here--according to the conventions already explained--in a form that can be inherited by subclasses of Accnt that could be defined later. Thus, SavAccnt inherits the rewrite rules for crediting and debiting accounts, and for transferring funds between accounts that had been defined for Accnt.

Let us illustrate the treatment of class inheritance with the system module resulting from the transformation of the module SAV-ACCNT introduced previously.

  mod SAV-ACCNT is 
    including CONFIGURATION .
    including ACCNT .
    sorts SavAccnt . 
    subsort SavAccnt < Cid . 
    subsort SavAccnt < Accnt . 
    op SavAccnt : -> SavAccnt . 
    op rate :_ : MachineInt -> Attribute . 
  endm

Prev Up