RosettaCodeData/Task/Polymorphism/OxygenBasic/polymorphism.basic

57 lines
1.1 KiB
Plaintext

type tpoint float xx,yy
type tcircle float xx,yy,rr
'==========
class point
'==========
'
has tpoint
'
method constructor (float x=0,y=0){this<=x,y}
method destructor {}
method V() as point {return @this}
method V(tpoint*a) {this<=a.xx,a.yy}
method V(point *a) {this<=a.xx,a.yy}
method X() as float {return xx}
method Y() as float {return yy}
method X(float a) {xx=a}
method Y(float a) {yy=a}
method clear() {this<=.0,.0}
method show() as string {return "x=" xx ", y=" yy }
'
end class
'===========
class circle
'===========
'
has point
float rr
'
method constructor (float x=.0,y=.0,r=1.0){this<=x,y,r}
method V(tcircle*a) {this<=a.xx,a.yy,a.rr}
method V(circle *a) {this<=a.xx,a.yy,a.rr}
method R() as float {return rr}
method R(float a) {rr=a}
method clear() {this<=.0,.0,.0}
method show() as string {return "x=" xx ", y=" yy ", r=" rr }
'
end class
'=====
'TESTS
'=====
new circle ca (r=.5)
new circle cb (x=10,y=10)
new circle cc (10,10,0.5)
cb.r="7.5" 'will convert a string value
cb.y=20
print cb.show 'result x=10, y=20 ,r=7.5
del ca : del cb : del cc