version 1.36, 1999/05/22 20:03:54
|
version 1.37, 1999/07/05 19:56:02
|
Line 7422 terminology: The derived class inherits
|
Line 7422 terminology: The derived class inherits
|
@cindex @file{objects.fs} |
@cindex @file{objects.fs} |
@cindex @file{oof.fs} |
@cindex @file{oof.fs} |
|
|
This section describes the @file{objects.fs} package. This material also has been published in @cite{Yet Another Forth Objects Package} by Anton Ertl and appeared in Forth Dimensions 19(2), pages 37--43 (@url{http://www.complang.tuwien.ac.at/forth/objects/objects.html}). |
This section describes the @file{objects.fs} package. This material also |
|
has been published in @cite{Yet Another Forth Objects Package} by Anton |
|
Ertl and appeared in Forth Dimensions 19(2), pages 37--43 |
|
(@url{http://www.complang.tuwien.ac.at/forth/objects/objects.html}). |
@c McKewan's and Zsoter's packages |
@c McKewan's and Zsoter's packages |
|
|
This section assumes that you have read @ref{Structures}. |
This section assumes that you have read @ref{Structures}. |
Line 7436 case-sensitive or not, special-purpose w
|
Line 7439 case-sensitive or not, special-purpose w
|
@menu |
@menu |
* Properties of the Objects model:: |
* Properties of the Objects model:: |
* Basic Objects Usage:: |
* Basic Objects Usage:: |
* The Objects base class:: |
* The Objects base class:: |
* Creating objects:: |
* Creating objects:: |
* Object-Oriented Programming Style:: |
* Object-Oriented Programming Style:: |
* Class Binding:: |
* Class Binding:: |
* Method conveniences:: |
* Method conveniences:: |
* Classes and Scoping:: |
* Classes and Scoping:: |
|
* Dividing classes:: |
* Object Interfaces:: |
* Object Interfaces:: |
* Objects Implementation:: |
* Objects Implementation:: |
* Objects Glossary:: |
* Objects Glossary:: |
Line 7794 end-class circle
|
Line 7798 end-class circle
|
@end example |
@end example |
|
|
|
|
@node Classes and Scoping, Object Interfaces, Method conveniences, Objects |
@node Classes and Scoping, Dividing classes, Method conveniences, Objects |
@subsubsection Classes and Scoping |
@subsubsection Classes and Scoping |
@cindex classes and scoping |
@cindex classes and scoping |
@cindex scoping and classes |
@cindex scoping and classes |
Line 7828 have several @code{protected}s without a
|
Line 7832 have several @code{protected}s without a
|
will restore the compilation word list in effect before the first of |
will restore the compilation word list in effect before the first of |
these @code{protected}s. |
these @code{protected}s. |
|
|
@node Object Interfaces, Objects Implementation, Classes and Scoping, Objects |
@node Dividing classes, Object Interfaces, Classes and Scoping, Objects |
|
@subsubsection Dividing classes |
|
@cindex Dividing classes |
|
@cindex @code{methods}...@code{end-methods} |
|
|
|
You may want to do the definition of methods separate from the |
|
definition of the class, its selectors, fields, and instance variables, |
|
i.e., separate the implementation from the definition. You can do this |
|
in the following way: |
|
|
|
@example |
|
graphical class |
|
inst-value radius |
|
end-class circle |
|
|
|
... \ do some other stuff |
|
|
|
circle methods \ now we are ready |
|
|
|
m: ( x y circle -- ) |
|
radius draw-circle ;m |
|
overrides draw |
|
|
|
m: ( n-radius circle -- ) |
|
[to-inst] radius ;m |
|
overrides construct |
|
|
|
end-methods |
|
@end example |
|
|
|
You can use several @code{methods}...@code{end-methods} sections. The |
|
only things you can do to the class in these sections are: defining |
|
methods, and overriding the class's selectors. You must not define new |
|
selectors or fields. |
|
|
|
Note that you often have to override a selector before using it. In |
|
particular, you usually have to override @code{construct} with a new |
|
method before you can invoke @code{heap-new} and friends. E.g., you |
|
must not create a circle before the @code{overrides construct} sequence |
|
in the example above. |
|
|
|
@node Object Interfaces, Objects Implementation, Dividing classes, Objects |
@subsubsection Object Interfaces |
@subsubsection Object Interfaces |
@cindex object interfaces |
@cindex object interfaces |
@cindex interfaces for objects |
@cindex interfaces for objects |
Line 7870 bar class
|
Line 7915 bar class
|
storage implementation |
storage implementation |
|
|
... overrides write |
... overrides write |
... overrides read |
... overrides read1 |
... |
... |
end-class foo |
end-class foo |
@end example |
@end example |
Line 8050 doc---objects-end-class
|
Line 8095 doc---objects-end-class
|
doc---objects-end-class-noname |
doc---objects-end-class-noname |
doc---objects-end-interface |
doc---objects-end-interface |
doc---objects-end-interface-noname |
doc---objects-end-interface-noname |
|
doc---objects-end-methods |
doc---objects-exitm |
doc---objects-exitm |
doc---objects-heap-new |
doc---objects-heap-new |
doc---objects-implementation |
doc---objects-implementation |
Line 8060 doc---objects-interface
|
Line 8106 doc---objects-interface
|
doc---objects-;m |
doc---objects-;m |
doc---objects-m: |
doc---objects-m: |
doc---objects-method |
doc---objects-method |
|
doc---objects-methods |
doc---objects-object |
doc---objects-object |
doc---objects-overrides |
doc---objects-overrides |
doc---objects-[parent] |
doc---objects-[parent] |