A qBeta program is a description of an object as shown by the following very simple example:
myProgram: obj
"Hello world\n".print
This program may be compiled and executed, which implies the generation of an object. This object executes the statement "Hello world\n".print, which prints the text "Hello world\n".
The following example shows the description of a Bank object containing a class pattern Account.
Bank: obj
Account(owner: var String):
balance: var integer
maxOverDraw: val -500
deposit(amount: var integer):
balance := balance + amount
withdraw(amount: var integer):
if (balance - amount >= maxOverDraw) :then
balance := balance - amount
:else
"Insufficient fund".print
Joe: obj Account("Joe")
Mary: ref Account
Mary := Account("Mary")
Joe.deposit(500)
Mary.deposit(300)
Joe.withdraw(150)
Mary := Joe
Class Account has the following attributes:
- A parameter
owner, which is a variable data-item of typeString. - A local data-item,
balance, which is a variable of typeinteger. - A local data-item,
maxOverDraw, which is a constant data-item of typeinteger. - Two local methods
depositandwithdraw, which each has a parameteramount. - The method
depositadds the value ofamountto the value ofbalance. - The method
withdrawexecuted anif:then:else statementthat checks if there is enough money on the account to withdraw amount. If not a message is printed.
The Bank object in addition to class Account has the following declarations and statements – referred to as items.
Joeis a constant reference to anAccount-object. This object is generated by the expressionAccount("Joe"),which is executed as part of the generation of theBankobject.- an object generated as part of the generation of the
Bankobject. This means thatJoeis a constant reference to anAccountobject. Maryis a variable reference to instances ofAccount- The statement
Mary := Account("Mary")implies that anAccount-object is generated with theString"Mary"as the actual parameter and a reference to this object is assigned to Mary. - The statement
Joe.deposit(500)invokes the methoddepositon the object referred to byJoewith 500 being the actual parameter. - The statement
Mary.desposit(300)in a similar way invokesdepositon the object referred to byMary. - The final statement
Mary := Joeimplies that the reference hold byJoeis assigned toMary, which means thatMarynow refers to the same object asJoe.
qBeta distinguishes between references and values and use the term datum to be either a reference or a value.
- A reference is a datum the uniquely refers to an object. Data-items declared using
objandrefmay hold references. - A value is a datum being a mathematical value such as an integer, a float, a Boolean, a char and a string. Data-items declared using
varandvalmay hold values.
The reason for distingiushing references and values is that there is a fundamental difference between these.
The object myBank is the only one of its kind and is called a singular object. This is in contrast to the objects generated from class Account where an arbitrary number of objects may be generated.


