Non OO code for demonstration:
Code: Select all
;- Structure Person
Structure Person
Name.s
*Where.Room ;<---- Cross Dependency Between Classes
EndStructure
;- Structure Room
Structure Room
Label.s
List *Peopple.Person()
EndStructure
;Instantiate a Room ---------------------------------
*objRoom.Room = AllocateMemory(SizeOf(Room))
InitializeStructure(*objRoom, Room)
*objRoom\Label = "Meeting Room"
;Instantiate and insert peopple1 ---------------------
AddElement(*objRoom\Peopple())
*objRoom\Peopple() = AllocateMemory(SizeOf(Room))
InitializeStructure(*objRoom\Peopple(), Room)
*objRoom\Peopple()\Name = "Billy"
*objRoom\Peopple()\Where = *objRoom
;Instantiate and insert peopple2 ---------------------
AddElement(*objRoom\Peopple())
*objRoom\Peopple() = AllocateMemory(SizeOf(Room))
InitializeStructure(*objRoom\Peopple(), Room)
*objRoom\Peopple()\Name = "Bob"
*objRoom\Peopple()\Where = *objRoom
;Print Results ---------------------------------------
Debug "RoomLabel: "+*objRoom\Label
ForEach *objRoom\Peopple()
Debug " Person: "+*objRoom\Peopple()\Name+" are in the "+*objRoom\Peopple()\Where\Label
Next
;ownTheRoom ------------------------------------------
;In this case, this is alot redundant, but is for comparison purposes only
*objRoom\Peopple()\Where\Label = *objRoom\Peopple()\Where\Label+" of "+*objRoom\Peopple()\Name ;*objRoom\Name = "Meeting Room of Bob"
Code: Select all
;- Structure Person
Class Person
Private Name.s
Private *Where.Room ;<---- Cross Dependency Between Classes
Public Method setName(Name.s)
This\Name = Name
EndMethod
Public Method.s getName()
MethodReturn This\Name
EndMethod
Public Method setRoom(*obj.Room) ;<---- Cross Dependency Between Classes [Error]
This\Where = *obj
EndMethod
Public Method.Room getRoom() ;<---- Cross Dependency Between Classes [Error]
MethodReturn This\Where
EndMethod
Public Method ownTheRoom()
;THIS WILL NEVER WORK UNLESS THERE IS SOME "PROCEDURE DECLARE" LIKE COMMAND FOR CLASSES
*obj.Room ;<---- Cross Dependency Between Classes [Error]
*obj = This\Where
*obj\setLabel(*obj\getLabel()+" of "+This\Name) ;<---- Cross Dependency Between Classes [Error]
EndMethod
EndClass
;- Structure Room
Class Room
Private Label.s
Private List *Peopple.Person()
Public Method setLabel(Label.s)
This\Label = Label
EndMethod
Public Method.s getLabel()
MethodReturn This\Label
EndMethod
Public Method addPeopple(*obj.Person)
AddElement(This\Peopple())
This\Peopple() = *obj
EndMethod
Public Method getPeopple()
MethodReturn This\Peopple()
EndMethod
Public Method Show()
Debug "RoomLabel: "+This\Label
ForEach This\Peopple()
*obj.Room = This\Peopple()\getRoom()
Debug " Person: "+This\Peopple()\getName()+" are in the "+*obj\getLabel() ;[Error]
Next
EndMethod
EndClass
;Instantiate a Room ---------------------------------
*objRoom.Room = NewObject.Room()
*objRoom\setLabel("Meeting Room")
;Instantiate and insert peopple1 ---------------------
*objPerson.Person
*objPerson = NewObject.Person()
*objPerson\setName("Billy")
*objPerson\setRoom(*objRoom)
*objRoom\addPeopple(*objPerson)
;Instantiate and insert peopple2 ---------------------
*objPerson = NewObject.Person()
*objPerson\setName("Bob")
*objPerson\setRoom(*objRoom)
*objRoom\addPeopple(*objPerson)
;Print Results ---------------------------------------
*objRoom\Show()
;ownTheRoom ------------------------------------------
*objPerson\ownTheRoom() ;But, due the line 24, it will never works
Code: Select all
;- Structure Person
Class Person
Private Name.s
Private *Where.Room ;<---- Cross Dependency Between Classes
Public Method setName(Name.s)
This\Name = Name
EndMethod
Public Method.s getName()
MethodReturn This\Name
EndMethod
Public Method setRoom(*obj) ;<---- Omitted the Where type/class
This\Where = *obj
EndMethod
Public Method getRoom() ;<---- Omitted the Return type/class
MethodReturn This\Where
EndMethod
Public Method ownTheRoom()
*obj = This\Where
;THIS WILL NEVER WORK UNLESS THERE IS SOME "PROCEDURE DECLARE" LIKE COMMAND FOR CLASSES
;*obj\setLabel(*obj\getLabel()+" of "+This\Name) ;<---- Cross Dependency Between Classes [Error]
EndMethod
EndClass
;- Structure Room
Class Room
Private Label.s
Private List *Peopple.Person()
Public Method setLabel(Label.s)
This\Label = Label
EndMethod
Public Method.s getLabel()
MethodReturn This\Label
EndMethod
Public Method addPeopple(*obj.Person)
AddElement(This\Peopple())
This\Peopple() = *obj
EndMethod
Public Method getPeopple()
MethodReturn This\Peopple()
EndMethod
Public Method Show()
Debug "RoomLabel: "+This\Label
ForEach This\Peopple()
*obj.Room = This\Peopple()\getRoom()
Debug " Person: "+This\Peopple()\getName()+" are in the "+*obj\getLabel(*obj) ;<--- Really wierd, since that
;Method has no parameters!
Next
EndMethod
EndClass
;Instantiate a Room ---------------------------------
*objRoom.Room = NewObject.Room()
*objRoom\setLabel("Meeting Room")
;Instantiate and insert peopple1 ---------------------
*objPerson.Person
*objPerson = NewObject.Person()
*objPerson\setName("Billy")
*objPerson\setRoom(*objRoom)
*objRoom\addPeopple(*objPerson)
;Instantiate and insert peopple2 ---------------------
*objPerson = NewObject.Person()
*objPerson\setName("Bob")
*objPerson\setRoom(*objRoom)
*objRoom\addPeopple(*objPerson)
;Print Results ---------------------------------------
*objRoom\Show()
;ownTheRoom ------------------------------------------
;*objPerson\ownTheRoom() ;But, due the line 24, it will never works
If we swap the declaration order of the classes then the Show() method would be the problem, because it wouldn't be able to access the Person method getName().
I guess there will not be an truly Cross Dependency support until unless there is a Declare/Interface (Like de Procedures Declare) command for the classes.
My conclusion is that SimpleOOP is not a usable solution for OO programming in PureBasic. There is another OO precompiler. The PureObject, I wonder if anyone knows if it has this same limitation.