SLIDE 12 Custom Description
– In some cases it might happen that there is no description provided to use with a model class.
– Money: amount and currency. – Url: scheme, domain, port, path, parameters, etc.
– Create your own description.
45
Your own Description
- Create a subclass of MAElementDescription.
- On the class-side override:
– #isAbstract to return false. – #label to return the name of the description.
- On the instance-side override:
– #kind to return the base-class. – #acceptMagritte: to enable visiting. – #validateSpecific: to validate.
- Create a view, if you want to use it for UI building.
46
Tips for Builders
- Have a look at existing descriptions.
- Carefully choose the right superclass.
- Reuse the behaviour from the superclass.
- Parsing, printing and (de)serialization is
implemented in vistiors:
– MAStringReader, MAStringWriter – MABinaryReader, MABinaryWriter
47
Custom View
– Custom descriptions mostly need a new view. – Applications might need a special view for existing descriptions to adapt a better user experience.
– Money: an input-field for the amount and a drop- down box to select the currency.
– Choose a different view or create your own.
48