11.2.1.2 Overview of default classes

The diagram of the core classes is:

     -class---------------
    | mbfl_default_object |-------------------------------
     ---------------------                                |
              ^                                           |
              | superclass                                |
              |                                           |
     -metaclass----------                                 |
    | mbfl_default_class |<--+--------------              |
     --------------------    |              |             |
       ^              |      | metaclass    | metaclass   | metaclass
       | superclass   |      |              |             |
       |               ------               |             |
       |                                    |             |
 -metaclass-------------------              |             |
| mbfl_default_abstract_class | ------------              |
 -----------------------------                            |
               ^                                          |
               |                                          |
                ------------------------------------------

The object mbfl_default_class is the default metaclass of classes in MBFL; we define new classes by instantiating mbfl_default_class or one of its subclasses; an instance of mbfl_default_class can only be a subclass of mbfl_default_object.

The class mbfl_default_class also has a metaclass: it is mbfl_default_class itself. The superclass of mbfl_default_class is mbfl_default_object.

An instance of mbfl_default_class is a Bash index array with the following layout:

datavar[0]      ⇒ _(METACLASS)
datavar[1]      ⇒ _(PARENT_CLASS)
datavar[2]      ⇒ class name as string
datavar[3]      ⇒ N = fields number
datavar[4]      ⇒ field 0 name as string
datavar[5]      ⇒ field 1 name as string
...
datavar[4+N-1]  ⇒ field N-1 name as string

being a mbfl_default_object an array element with key ‘0’ is always present and its value is the instance’s class. We instantiate mbfl_default_class by using its instance constructor, which is the function mbfl_default_class_define().

If we define the class colour as follows:

mbfl_default_class_declare(COLOUR)

mbfl_default_class_define _(COLOUR) _(mbfl_default_object) 'colour' red green blue

the layout of the colour array is:

datavar[0]      ⇒ _(mbfl_default_class)
datavar[1]      ⇒ _(mbfl_default_object)
datavar[2]      ⇒ 'colour'
datavar[3]      ⇒ 3
datavar[4]      ⇒ 'red'
datavar[5]      ⇒ 'green'
datavar[6]      ⇒ 'blue'

This document describes version 3.0.0-devel.9 of Marcos Bash Functions Library.