Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
38
Task/Polymorphism/BBC-BASIC/polymorphism.basic
Normal file
38
Task/Polymorphism/BBC-BASIC/polymorphism.basic
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
INSTALL @lib$ + "CLASSLIB"
|
||||
|
||||
REM Create parent class with void 'doprint' method:
|
||||
DIM PrintableShape{doprint}
|
||||
PROC_class(PrintableShape{})
|
||||
|
||||
REM Create derived class for Point:
|
||||
DIM Point{x#, y#, setxy, retx, rety, @constructor, @@destructor}
|
||||
PROC_inherit(Point{}, PrintableShape{})
|
||||
DEF Point.setxy (x,y) : Point.x# = x : Point.y# = y : ENDPROC
|
||||
DEF Point.retx = Point.x#
|
||||
DEF Point.rety = Point.y#
|
||||
DEF Point.@constructor Point.x# = 1.23 : Point.y# = 4.56 : ENDPROC
|
||||
DEF Point.@@destructor : ENDPROC
|
||||
DEF Point.doprint : PRINT Point.x#, Point.y# : ENDPROC
|
||||
PROC_class(Point{})
|
||||
|
||||
REM Create derived class for Circle:
|
||||
DIM Circle{x#, y#, r#, setxy, setr, retx, rety, retr, @con, @@des}
|
||||
PROC_inherit(Circle{}, PrintableShape{})
|
||||
DEF Circle.setxy (x,y) : Circle.x# = x : Circle.y# = y : ENDPROC
|
||||
DEF Circle.setr (r) : Circle.r# = r : ENDPROC
|
||||
DEF Circle.retx = Circle.x#
|
||||
DEF Circle.rety = Circle.y#
|
||||
DEF Circle.retr = Circle.r#
|
||||
DEF Circle.@con Circle.x# = 3.2 : Circle.y# = 6.5 : Circle.r# = 7 : ENDPROC
|
||||
DEF Circle.@@des : ENDPROC
|
||||
DEF Circle.doprint : PRINT Circle.x#, Circle.y#, Circle.r# : ENDPROC
|
||||
PROC_class(Circle{})
|
||||
|
||||
REM Test the polymorphic 'doprint' function:
|
||||
PROC_new(mypoint{}, Point{})
|
||||
PROC(mypoint.doprint)
|
||||
PROC_discard(mypoint{})
|
||||
PROC_new(mycircle{}, Circle{})
|
||||
PROC(mycircle.doprint)
|
||||
PROC_discard(mycircle{})
|
||||
END
|
||||
Loading…
Add table
Add a link
Reference in a new issue