The basic object oriented patterns are the object pattern and the object oriented variants of the basic patterns.
The object pattern functions as the implicit superpattern: for all patterns which do not have any explicit superpattern:. The pattern object is defined as follows:
object: (* general superpattern: *) (# _struc: (# exit this(object)## #); _new: (# O: ^object do ... exit O[] #) do inner #);
The attribute _struc returns a reference to the structure of the current object (i.e. a pattern reference to the pattern from which this object was created). The attribute _struc is maintained in v1.6 for backward-compatability reasons. It will be removed in next release, since it will become obsolite, since O## is allowed in the case where O is the name of an object. However, previous releases of the compiler disallows this construct in some cases due to an error. Only in these cases, it is recommended to use the O._struc construct.
The attribute _new returns a new object, that is qualified exactly as THIS(object). This new object is default initialized.
All patterns except char, integer, real, boolean, true and false are subpatterns of Object. To enable handling integers, reals, characters and booleans like any other objects in the system, the patterns charObject, integerObject, realObject, booleanObject, trueObject, and falseObject have been introduced. They are genuine patterns, corresponding to the basic patterns, described above. They are specializations of Object that can be used instead of the basic patterns. They have all properties ordinary patterns have (in contrast to the basic patterns).
The charValue, integerValue, booleanValue, and realValue patterns are object oriented variants of the basic patterns (i.e. built-in patterns). They are used in all cases where a value of the given type is needed. E.g. a booleanValue may be used as superpattern for patterns returning boolean results.
These patterns are subpatterns: of the charValue, integerValue, etc. patterns above, and gives the final functionality to allow these variants of the basic patterns to be used a genuine patterns.
These patterns can for instance be utilized when programming general data structures. Consider a data structure list which defines its element type as a virtual Object.
list: (# element :< object; insert: (# e: ^element enter e[] do ... #) remove: (# e: ^element do ... exit e[] #) #)
When list is applied in a specific application, the element type is bound. The following is an example of how a list of integers and a list of editors can be declared and manipulated:
(# integerList: @list(# element::< integerObject #); editor: (# window: ... menus: ... cut: ... copy: ... paste: ... #); ed: ^editor; editorList: @list(# element::< editor #); io: ^integerObject; do &integerObject[] -> io[]; 7 -> io; io[] -> integerList.insert; ... editorList.remove -> ed[]; ... #)
Basic Libraries - Reference Manual | © 1990-2004 Mjølner Informatics |
[Modified: Monday October 23rd 2000 at 11:49]
|