1 require m
-inherited minioof
6 ." ROOT OBJECT=0x" object
.hex8 cr
16 ." BUTTON=0x" Button
.hex8 cr
18 ;; Now
, implement the two methods
, draw and init
:
22 ." x=" r@ x @
0 .r
." ; y=" r@ y @
0 .r
." ; text=<"
23 r@ text @ r
> len @ type
28 :noname
( addr u o
-- ) >r
29 ." INIT: class=0x" r@ @class
.hex8
." ; parentclass=0x" r@ @class @class
-parent
.hex8 cr
30 6 r@ x
! 12 r@ y
! dup r@ len
!
31 ;; allocate string at
"here"
32 dup n
-allot dup r
> text
! swap move
36 ;; For inheritance
, we define a class bold
-button
, with no new data and no new methods
.
40 ." BOLD-BUTTON=0x" Bold
-Button
.hex8 cr
42 : bold
( .ansi
-escape
." 1m" ) ." [BOLD]" ;
43 : normal
( .ansi
-escape
." 0m" ) ." [NORMAL]" ;
45 \ this does early
(static
) binding
46 \
:noname
( o
-- ) bold
[ Button
:: draw
] normal
;
47 \ this does dynamic binding
48 \
:noname
( o
-- ) bold dup @class @class
-parent m
-invoke draw normal
;
49 \ or this
(dynamic too
)
50 :noname
( o
-- ) bold m
-inherited draw normal
;
51 Bold
-Button defines draw
53 ;; And finally
, some code
to demonstrate how
to create objects and apply methods
:
55 Button new constant foo
59 Bold
-Button new constant bar