To keep a code base in good order, new class declarations should be at the top–level scope:
mbfl_default_class_declare(MY_PERSON) mbfl_default_class_define _(MY_PERSON) _(mbfl_default_object) 'my_person' name surname
no matter where we declare them: new functions will be defined as constructor, predicate, field accessors and mutators, and those are at the top–level. We can declare a class at the top–level and define it in a function; MBFL itself puts some class definitions and instances definitions in an initialisation function:
mbfl_default_class_declare(MY_PERSON)
function my_initialise_this_module () {
mbfl_default_class_define _(MY_PERSON) _(mbfl_default_object) 'my_person' name surname
}
To be used without conflicts: both global class’s proxy variables and class identifiers must be unique in the whole script.
Non–class instances can be declared and defined both at the top–level scope or in a function scope. Usually we declare and define an instance in the scope of a function:
function do_something () {
mbfl_default_object_declare(MAINTAINER)
my_person_define _(MAINTAINER) _(MY_PERSON) 'Marco' 'Maggi'
# do something with _(MAINTAINER)
}
we can declare and define an instance at the top–level scope:
mbfl_default_object_declare(MY_MAINTAINER)
my_person_define _(MY_MAINTAINER) _(MY_PERSON) 'Marco' 'Maggi'
function do_something () {
# do something with _(MY_MAINTAINER)
}
and we can declare at the top–level and define all from within a function:
function do_something () }
mbfl_declare_varref(MAINTAINER)
build_it_var _(MAINTAINER)
# do something with _(MAINTAINER)
}
function built_it_var () {
mbfl_mandatory_nameref_parameter(RV, 1, result variable)
mbfl_default_object_declare_global(MAINTAINER)
my_person_define _(MAINTAINER) _(MY_PERSON) 'Marco' 'Maggi'
# do something with _(MAINTAINER)
RV=_(MAINTAINER)
}
This document describes version 3.0.0-devel.9 of Marcos Bash Functions Library.