A part pattern is a pattern that is physically part of an object. This corresponds to textually
nesting of procedures and classes and is often called block-structure. It is well known from
mainstream object-oriented languages that the attributes of an object may be
procedures/methods, but classes as attributes are quite uncommon. In BETA class nesting
may be used as in the following example:
Document:
(# content: @text; pos: @integer;
new: ...; open: ...; close: ...;
Selection:
(#
first,
last:
@integer;
cut: (#do (first,last)->content.delete #);
copy: (#exit (first,last)->content.copy #);
paste:
(#
destination:
^document
enter
destination[]
do
(first,last)->destination.content.insert
#)
#);
#);
D1,D2: @Document;
S1,S2: @D1.Selection;
S3,S4: @D2.Selection
A document-object consists of a content that is a text. A variable pos contains the current
(cursor) position in the document. A document has operations new, open and close. In
addition a document object has a class pattern attribute Selection that is an object
representing a selection in the document. A selection is characterised by an interval in the
content, represented by the integers first and last. A selection has three operations,
cut, copy and paste. Cut deletes the selection from content, copy returns a copy of the
selection and paste copy the selection into a destination document.
Since Selection is a pattern declared textually within Document, each instance of
Document has its own Selection class. The documents D1 and D2 thus each has a
class D1.Selection and D2.Selection that are in fact different classes. The objects
S1 and S2 are instances of D1.Selection and S2, S3 are instances of
D2.Selection.
Since Selection is part of a Document object, it is possible from a Selection
object refer to variables and operations in the enclosing Document object. For example
S1.cut will execute the operation
(first,last)->content.delete
where content will refer to the content variable in the enclosing D1 document.
Textual nesting of classes is a common used feature in most of the Mjølner BETA
libraries and application frameworks. The above example is a simplified example of how
components (like class document) and anchors (like class Selection) are represented in the
DEVISE hypermedia framework [GT94] .
Part patterns/nested patterns are similar to part objects in the sense that they are a fixed
part of an object. Like it is possible to have references to objects, it is also possible to have
references to patterns. Such references are closures in the sense that they refer patterns and