| Did you know ... | Search Documentation: |
| Predicate use_class_template/1 |
use_class_template(+TemplateClass)Suppose an application requires specialisations of several primitive graphical classes. Three ways are available: use pce_expand_class/1 on one of the super-classes (unsafe, as the methods become available to all users), make subclasses of every class needing the extension and duplicate the source (bad: hurts maintenance), or use a class template.
To use a template: first create a subclass of class template
and define all variables and methods that need to be attached to the
target class. Then write:
:- pce_begin_class(mybox, box). :- use_class_template(my_graphical_extensions). :- pce_end_class.
This behaves exactly as if all text defining
my_graphical_extensions were duplicated at the
use_class_template/1
call. The method implementation (the Prolog predicate) is shared between
the classes that use the template.
Note that you can normally not create instances of the template class itself since it may lack methods that need to be refined in the target classes. Note also that you cannot further refine a method imported from a template in the same class -- the import behaves like text duplication, so a new definition simply overwrites the one from the template. You can refine the method in a subclass.