Now I have to give my humble opinion.
Eddy's first example is not oop at all because he never uses the variables inside the structure (Eddy recognizes itself later on that's it's not oop...).
----------------------------------------------
El_Choni's example is good, but is not scalable. With scalable I mean all Procedures need to be set AFTER the OBJECT is initialized.
In real life situation this would result in:
Code: Select all
;- start main
;user creates his object named MyObject
MyObject.OBJECT
;now the user HAS TO SET all procs to get it working
MyObject\proc1 = @MyObjectProcedure1()
MyObject\proc2 = @MyObjectProcedure2()
MyObject\proc3 = @MyObjectProcedure3()
MyObject\proc4 = @MyObjectProcedure4()
MyObject\proc5 = @MyObjectProcedure5()
MyObject\proc6 = @MyObjectProcedure6()
;and even more procs
;the user can set the properties of object
MyObject\a = 16
;the user can call his methods of object
MyObject\proc(MyObject, 1, 2)
If the setting of all the Procedures/Methods could be done before the user assigns a class to his object (MyObject.OBJECT) this solution would be another good way to do it.
----------------------------------------------
Phantas example is a also good but MAIN actually starts with GLOBAL NEWLIST.
So users code would look like:
Code: Select all
;- start main
;user has to create a list
Global NewList MyObject_List.MyObject()
;user has to set the procedures/ methods
Procedure.l CreateThisClass()
AddElement(MyObject_List())
MyObject_List()\StoreThis = @This()
MyObject_List()\GetThat = @That()
ProcedureReturn @MyObject_List()
EndProcedure
;user initializes his class
;List name is "hard wired" and can't be changed on the fly
CreateThisClass()
;user is calling his methods
;code seems to be pretty long
MyObject_List()\StoreThis(@MyObject_List(),347)
MyObject_List()\GetThat(@MyObject_List())
If Phantas code can be changed to:
Code: Select all
;- start main
;user has to create a list
Global NewList MyObject_List.MyObject()
;user initializes his class
;here all procedures/methods are initialized automatically
CreateThisClass(@MyObject_List())
;user is calling his methods
MyObject_List()\StoreThis(347)
MyObject_List()\GetThat()
this solution would be another good way to do it.
----------------------------------------------
But now look at the main code of my first post:
Code: Select all
;- start main:
;user creates his object named "m" as "MyObject" class
;user initializes his class with "CreateThisClass()"
;all Procedures/Methods are set automatically
m.MyObject = CreateThisClass()
;user uses his methods
m\StoreThis(347)
m\GetThat()
End
For the user the last code is far more simpler to use.
The Properties can only be accessed through Methods, which is actually not a bad thing.
Maybe the same can be achieved with prototypes...
Hope I didn't upset anybody, it wasn't my intention.
In fact if there is a simpler oop way using prototypes instead of interfaces this would be great.
Please keep the ideas coming...
