Re: Structs
- Posted by begin Jun 22, 2019
- 4685 views
wow Pete this great i like to suggest some things, that, i am sure i will to have to edit. but here it goes:
-- The object-oriented features of PHIX all come from classes. The class hierarchy has as its root the class Object.
-- Object defines a minimum level of functionality that each derived class has, and a default implementation for that functionality.
-- Classes are programmer defined types. Support for classes are what makes PHIX an object oriented language, giving it encapsulation,
-- inheritance, and polymorphism. PHIX classes support the single inheritance paradigm, extended by adding support for abstract classes.
-- A class can be exported, which means its name and all its non-private members (those that are not decorated with public) are exposed
-- externally to the DLL or EXE
-- All member functions of 'synchronized' (decorator for a class) classes are synchronized for threads.
-- Classes can not be nested
-- optinal '(' with 'T' list for generics ')', when brackets are used, atleast one 'T' has to be in the list
-- if a class is decorated with [public] it is visible outside the definition file
-- if a class is decorated with [abstract] class
-- Class methods are defined exactly like a normal procedure or function procedure.
-- Abstract procedures/functions can be declared within an abstract class. Abstract procedures are not implemented within a class.
-- They are simply placeholders defining how a given method is implemented in classes which inherit an abstract class.
-- optinal '(' with 'T' list for generics ')', when brackets are used, atleast one 'T' has to be in the list
-- Base class construction is done by calling the base class constructor by the name 'super'
-- ALL CLASSES METHODS ARE VIRTUAL
-- [abstract | override] Procedure/function header
-- Class methods are defined exactly like a normal procedure or function procedure. Abstract procedures can be declared within an abstract class.
-- Abstract procedures are not implemented within a class. They are simply placeholders defining how a given method is implemented in classes which
-- inherit an abstract class.
-- To override a class method defined in an inherited class you prefix the method definition with the OVERRIDE keyword. Overridden methods preserve the
-- interface but replace the implementation. Method calls will always refer to the method implementation according to the dynamic type of a object.
-- By overriding a method no new component is established. The existing method is replaced with the overridden method.
-- Methods that are decorated with 'final' can not be overriden.
class point
atom x, y, w, h -- initialized with NAN
string description -- initialized with ""
public dummyint = 1 -- if = 1 is omitted, it should also be initialzed, maybe to the larges neg. INT possible
public sequ = {4, 5, 6} -- or default initialized with {}
point() -- initializer, does nothing
end point
point(atom x, atom y, atom w, atom h) -- initializer overloaded
.x = x .y = y .w = w .h = h ------- the period '.' is short for this
end point
point(atom x, atom y, string description) -- initializer overloaded
.x = x .y = y .description = description
end point
public procedure description(string descript)
.description = descript
end description
public function description()
return .description
end function
public procedure setxy(atom x, atom y)
.x = x .y = y
end description
public procedure getx()
return .x
end description
public procedure getMultiplierSequence()
return .sequ
end description
end class
-- make a new class - maybe there should be a new keyword 'class', but object should be able to be synonym
object p1 = new(point()) -- or
object p2 = new(point(1,2,3,4)) -- or
object p3 = new(point(1,2,"some text"))
-- make a new sequence of classes
sequence s1 = new(point(1,2,"some text"), 100)
-- copy a sequence of classes. s2 contains a distinct new deep copy of s1, therefore s2[1] != s1[1], but with same data content
sequence s2 = s1
sequence s2[2] = {} -- s2[2] is empty, s1[2] is not
bool test = ISMEMBER(s2[2], point) -- returns true
-- destroy a/the class/es
destroy(p2)
p3 = {}
s1 = {}
-- use
p3.x = 0.01 -- error variable not public, must be set by setxy(atom x, atom y) or some other defined method
p3.dummyint = 1 -- correct is public
integer testint = p3.dummyint -- correct is public
sequence w = sq_mul(5, p3.sequ) -- w is {20, 25, 30} (out of phix help)
--or
w = sq_mul(5, p3.getMultiplierSequence())
--sequence use
s1[50].setxy(0.1, 0.2)
-- inherit class point
class circle extend point -- single inheritance, the compiler check for circulars an pukes if necessary.
atom radius
super(1,2,3,4)
end class
-- abstract classes describe a list of functions that a class that inherits from the abstract class must implement.
-- A class that implements an abstract class can be converted to a reference to that abstract class.
abstract class phix1
procedure foo()
function bar(integer x)
final procedure finalproc(integer x) -- this procedure or function may not be implemented in a class
...
end procedure
end class
-- An instance of an abstract class cannot be created.
class phixC extend point implements phix1 -- ,phix2, ..
function bar(integer x) -- ok
...
end procedure
procedure foo() -- ok
...
end procedure
procedure finalproc() -- error, cannot override final finalproc
...
end procedure
end class

