I have added inheritance to the above example.
' ScriptBasic OOP Example
MODULE Customer
CONST cname = "cname"
CONST addr1 = "addr1"
CONST addr2 = "addr2"
instance = 0
' Default property settings
_cname[0] = ""
_addr1[0] = ""
_addr2[0] = ""
property{cname} = _cname[0]
property{addr1} = _addr1[0]
property{addr2} = _addr2[0]
FUNCTION GetName(object)
GetName = property{cname}[object]
END FUNCTION
FUNCTION SetName(object,value)
property{cname}[object] = value
END FUNCTION
FUNCTION GetAddr1(object)
GetAddr1 = property{addr1}[object]
END FUNCTION
FUNCTION SetAddr1(object,value)
property{addr1}[object] = value
END FUNCTION
FUNCTION GetAddr2(object)
GetAddr2 = property{addr2}[object]
END FUNCTION
FUNCTION SetAddr2(object,value)
property{addr2}[object] = value
END FUNCTION
FUNCTION New(base)
instance += 1
IF base = undef THEN
_cname[instance] = _cname[0]
_addr1[instance] = _addr1[0]
_addr2[instance] = _addr2[0]
ELSE
REF property{cname}[instance] = property{cname}[base]
REF property{addr1}[instance] = property{addr1}[base]
REF property{addr2}[instance] = property{addr2}[base]
END IF
new = instance
END FUNCTION
FUNCTION Inherit(base)
instance += 1
property{cname}[instance] = property{cname}[base]
property{addr1}[instance] = property{addr1}[base]
property{addr2}[instance] = property{addr2}[base]
Inherit = instance
END FUNCTION
FUNCTION Destroy(object)
_cname[object] = undef
_addr1[object] = undef
_addr2[object] = undef
END FUNCTION
END MODULE
'
' MAIN
'
cust1 = customer::New()
customer::SetName(cust1,"John Doe")
customer::SetAddr1(cust1,"123 Main St.")
customer::SetAddr2(cust1,"Anytown, USA")
cust2 = customer::Inherit(cust1)
PRINT customer::GetName(cust2),"\n"
PRINT customer::GetAddr1(cust2),"\n"
PRINT customer::GetAddr2(cust2),"\n"
PRINTNL
customer::SetName(cust2,"Mary Smith")
PRINT customer::GetName(cust1),"\n"
PRINT customer::GetName(cust2),"\n"
customer::Destroy(cust1)
customer::Destroy(cust2)
C:\scriptbasic\test>custobj
John Doe
123 Main St.
Anytown, USA
John Doe
Mary Smith
C:\scriptbasic\test>