It is currently Thu Nov 14, 2019 11:08 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: What's the most up-to-date OOP framework for PB?
PostPosted: Sat Nov 10, 2012 12:41 am 
Offline
Addict
Addict

Joined: Thu Nov 01, 2007 5:37 pm
Posts: 1981
Location: Germany
What is the latest / most up-to-date / best working OOP "framework" for PureBasic?

I just found this one. Unfortunately the website seems to be down: PureObject - PureBasic OOP support (latest post of developer on Feb 07, 2010)
There is another one though: SimpleOOP - Opensource Precompiler (non-official forum; latest post of developer on Jan 13, 2011)
And there is also srod's tutorial: Using OOP in Purebasic (his website; last updated on May 24, 2012)

Is there anything else? Which one do you recommend?

(Please no OOP discussion... ;) )

_________________
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!


Top
 Profile  
Reply with quote  
 Post subject: Re: What's the most up-to-date OOP framework for PB?
PostPosted: Sat Nov 10, 2012 12:50 am 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3114
Location: Boston, MA
You should also add Hydrate's excellent class example without interfaces.
I use this approach for my simple class based libraries and there is no pre-processor or interfaces. :wink:

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: What's the most up-to-date OOP framework for PB?
PostPosted: Sat Nov 10, 2012 1:25 am 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 31, 2005 11:09 pm
Posts: 3693
Location: Italy
Well, a OO preprocessor hide all the internal complexity and can do an amount of work behind the scene you will be mad to do directly so it's really different from using interfaces and vtables like shown in srod's tutorial.

There is another tutorial from Drac here: viewtopic.php?t=15032

If you don't mind to deal with some of that complexity I can post the include I use for my classes. It's simply an include with some macros and a template file I fill in every time I start a new class.

Don't know if it's your cup of tea but if want I can post it. It's for basic objects, simply an object and its methods. Nothing more is supported since I don't need more.

But I still think probably it's something only myself can like and it's time wasted to post it :)

_________________
[ My little PureBasic review ]


Top
 Profile  
Reply with quote  
 Post subject: Re: What's the most up-to-date OOP framework for PB?
PostPosted: Sat Nov 10, 2012 11:04 am 
Offline
Addict
Addict

Joined: Thu Nov 01, 2007 5:37 pm
Posts: 1981
Location: Germany
Well, I noticed that I have to restructure some of my code because it's getting hard to follow the program logic when basically everything can be changed/accessed from anywhere...
So as I understand the OOP approach seems to be a good way to (1) clean up the code, (2) move related functionality in to autonomous objects and to (3) increase reusability even further (I'm already using tons of general include files).

I don't think I'll need advanced OOP stuff. Right now I'm only interested in classes with fields, de-/constructor, (private) methods. I just don't know how this can be implemented in PureBasic the most efficient way.

_________________
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!


Top
 Profile  
Reply with quote  
 Post subject: Re: What's the most up-to-date OOP framework for PB?
PostPosted: Sat Nov 10, 2012 11:38 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Wed Oct 29, 2003 4:35 pm
Posts: 10525
Location: Beyond the pale...
Do it by hand! :wink:

Once you get used to it you can bash out the basic structure of even a quite complex class in minutes. The vTable is a very minor detail. You have a class-creation function and a suitable \Destroy() method and you're hot to trot!

I use interfaces for exactly the reason you suggested; helps me structure my code better. Hardest part is figuring out how to break your program down into a set of appropriate classes.

Mind you, I can pick up my code weeks later and still have no idea how it works!

_________________
I may look like a mule, but I'm not a complete ass.


Top
 Profile  
Reply with quote  
 Post subject: Re: What's the most up-to-date OOP framework for PB?
PostPosted: Sat Nov 10, 2012 7:56 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 3406
Location: New Zealand
I'd agree with Srod, do it by hand rather than using a preprocessor or write some macros


Top
 Profile  
Reply with quote  
 Post subject: Re: What's the most up-to-date OOP framework for PB?
PostPosted: Sat Nov 10, 2012 8:36 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue Apr 24, 2012 5:08 pm
Posts: 542
Location: Ontario, Canada
Yes, do it by hand. You have much more control over the code.

Using all the above references we devised a set of macros that allowed us to code classes without worrying about PB's quirky pointer syntax.

The following edited code shows the mainline module of one of our packages and its associated class. The "AppDesign" procedure would normally contain code to create the rest of the application, which is implemented entirely with classes.

Package mainline code:

Code:
;===============================================
;
;  start of package:  DvsML06.pb
;
;===============================================
;
;  This is the mainline code for the
;  DVS Mildred package.
;
;===============================================
;
;  common include files
;
IncludeFile "modConstant.pbi"                                                  ; Global Constants
IncludeFile "modMacro.pbi"                                                     ; Global Macros
IncludeFile "modStructure.pbi"                                                 ; Global Structures
;
;-----------------------------------------------
;
;  file class interfaces
;
IncludeFile "objFile195.pbi"                                                   ; Structures
IncludeFile "objFile229.pbi"                                                   ; Constants
IncludeFile "objFile231.pbi"                                                   ; Modules
IncludeFile "objFile233.pbi"                                                   ; Elements
IncludeFile "objFile250.pbi"                                                   ; Messages
;
;-----------------------------------------------
;
;  module class interfaces
;
IncludeFile "objApplication.pbi"                                               ; Application Class
IncludeFile "objContainer.pbi"                                                 ; Container Class
IncludeFile "objDD.pbi"                                                        ; Data Dictionary Support Class
IncludeFile "objGadget.pbi"                                                    ; Generic Gadget Class
IncludeFile "objDvsam.pbi"                                                     ; Dvsam Class
;
;-----------------------------------------------
;
;  program class interfaces
;
;
;-----------------------------------------------
;
;  package class interface
;
IncludeFile "objDvsML06.pbi"
;
;-----------------------------------------------
;
;  global objects
;
  GlobalObject(gloApp, objApplication)                                         ; 16138 : application object
  GlobalObject(gloDD, objDD)                                                   ; 16397 : data dictionary support object
;
;-----------------------------------------------
;
;  file classes
;
IncludeFile "clsFile195.pbi"                                                   ; Structures
IncludeFile "clsFile229.pbi"                                                   ; Constants
IncludeFile "clsFile231.pbi"                                                   ; Modules
IncludeFile "clsFile233.pbi"                                                   ; Elements
IncludeFile "clsFile250.pbi"                                                   ; Messages
;
;-----------------------------------------------
;
;  module classes
;
IncludeFile "clsApplication.pbi"                                               ; Application Class
IncludeFile "clsContainer.pbi"                                                 ; Container Class
IncludeFile "clsDD.pbi"                                                        ; Data Dictionary Support Class
IncludeFile "clsGadget.pbi"                                                    ; Generic Gadget Class
IncludeFile "clsDvsam.pbi"                                                     ; Dvsam Class
;
;-----------------------------------------------
;
;  program classes
;
;
;-----------------------------------------------
;
;  package class
;
IncludeFile "clsDvsML06.pbi"
;
;-----------------------------------------------
;
;  create global objects
;
  gloApp = CreateObject(Application)                                           ; 16138 : application object
  gloDD = CreateObject(DD)                                                     ; 16397 : data dictionary support object
;
;-----------------------------------------------
;
;  package mainline
;
  GlobalObject(gloDvsML06, objDvsML06)
  gloDvsML06 = CreateObject(DvsML06)
  ObjectCall(gloDvsML06, Main) ()
  gloDvsML06 = DestroyObject(gloDvsML06)
;
;-----------------------------------------------
;
;  destroy global objects
;
  gloDD = DestroyObject(gloDD)                                                 ; 16397 : data dictionary support object
  gloApp = DestroyObject(gloApp)                                               ; 16138 : application object
;
;-----------------------------------------------
;
;  end of package:  DvsML06.pb
;
End
;
;===============================================


Package interface:

Code:
;===============================================
;
;  DvsML06 class interface  :  DVS Mildred
;
;===============================================
;
;  Interface
;
DeclareExternalFunction(DvsML06, Create, typObject) ()
;
Interface objDvsML06
  Func(Destroy, typObject) ()
  Func(Clone,   typObject) ()
  Subr(Main)      ()
EndInterface
;
;===============================================
;  end of  :  DvsML06 Class Interface
;===============================================


Package class:

Code:
;===============================================
;
;  clsDvsML06.pbi  :  class methods  :  DVS Mildred
;
;===============================================
;
;  Properties
;
Structure strDvsML06
;
;  primary  properties
;
  FieldPointer(prpVirtualTable)                                                ; 16393 : pointer to the class virtual table
  Field(priReferenceCount, typInt32)                                           ; 16394 : class reference count
;
;  private properties
;
  Field(proAppContainer, objContainer)                                         ; 16085 : ref to the main application container object
;
EndStructure
;
;===============================================
;
;  Private Declares
;
DeclarePrivateSubroutine(DvsML06, Constructor) (ByVal(Me, strDvsML06))
DeclarePrivateSubroutine(DvsML06, Destructor)  (ByVal(Me, strDvsML06))
DeclarePrivateSubroutine(DvsML06, AppDesign)   (ByVal(Me, strDvsML06))
;
;===============================================
;
;  Primary Methods
;
;-----------------------------------------------
;
ExternalFunction(DvsML06, Create, typObject) ()
;
;  Create                              create a class instance
;
  Local(Me, strDvsML06)

  Me = AllocateMemory(SizeOf(strDvsML06))
  If IsObject(Me)
    InitializeStructure(Me, strDvsML06)
    Me\prpVirtualTable   = LabelPtr(DvsML06, VirtualTable)
    Me\priReferenceCount = 1
    ClassCall(DvsML06, Constructor) (Me)
  EndIf
  ProcedureReturn Me
EndFunction
;
;-----------------------------------------------
;
ExternalFunction(DvsML06, Destroy, typObject) (ByVal(Me, strDvsML06))
;
;  Destroy                             destroy a class instance
;
  If IsObject(Me)
    If Me\priReferenceCount > 1
      Me\priReferenceCount = Me\priReferenceCount - 1
    Else
      ClassCall(DvsML06, Destructor) (Me)
      ClearStructure(Me, strDvsML06)
      FreeMemory(Me)
    EndIf
  EndIf
  ProcedureReturn 0
EndFunction
;
;-----------------------------------------------
;
ExternalFunction(DvsML06, Clone, typObject) (ByVal(Me, strDvsML06))
;
;  Clone                               clone a class instance
;
  If IsObject(Me)
    Me\priReferenceCount = Me\priReferenceCount + 1
  EndIf
  ProcedureReturn Me
EndFunction
;
;===============================================
;
;  External Methods
;
;-----------------------------------------------
;
ExternalSubroutine(DvsML06, Main) (ByVal(Me, strDvsML06))
;
;  Main                                package mainline procedure
;

  Set(Me\proAppContainer, exsCaption, "DVS Mildred")                           ; 15328 : caption text
  Set(Me\proAppContainer, exiBaseWidth, 1280)                                  ; 16415 : nominal width of the gui object (pixels)
  Set(Me\proAppContainer, exiBaseHeight, 800)                                  ; 16416 : nominal height of the gui object (pixels)
  Set(Me\proAppContainer, exlResizeAllowed, True)                              ; 16405 : true = gui object can be resized
  Set(Me\proAppContainer, exlHorizontalAlignment, True)                        ; 16409 : true = horizontal gui object alignment is allowed
  Set(Me\proAppContainer, exiHorizontalAlignmentMode, #iGUI_ALIGN_FILL)        ; 16408 : fill, start, end, centre
  Set(Me\proAppContainer, exlVerticalAlignment, True)                          ; 16411 : true = vertical gui object alignment is allowed
  Set(Me\proAppContainer, exiVerticalAlignmentMode, #iGUI_ALIGN_FILL)          ; 16410 : fill, start, end, centre
  SetCallBack(Me\proAppContainer, expCBDesign, DvsML06, AppDesign)             ; create a callback pointer
  ObjectCall(Me\proAppContainer, Attach) ()                                    ; attach the application container

  ObjectCall(gloApp, ProcessEvents) ()                                         ; process the event loop

EndSubroutine
;
;===============================================
;
;  Private Methods
;
;-----------------------------------------------
;
PrivateSubroutine(DvsML06, Constructor) (ByVal(Me, strDvsML06))
;
;  Constructor                         package class contructor
;

  Me\proAppContainer = CreateObject(Container)                                 ; 16085 : ref to the main application container object

EndSubroutine
;
;-----------------------------------------------
;
PrivateSubroutine(DvsML06, Destructor) (ByVal(Me, strDvsML06))
;
;  Destructor                          package class destructor
;

  Me\proAppContainer = DestroyObject(Me\proAppContainer)                       ; 16085 : ref to the main application container object

EndSubroutine
;
;-----------------------------------------------
;
PrivateSubroutine(DvsML06, AppDesign) (ByVal(Me, strDvsML06))
;
;  AppDesign                           design the application window
;

EndSubroutine
;
;===============================================
;
;  Virtual Table
;
DataSection
  Label(DvsML06, VirtualTable)
;
;  primary  methods
;
  InterfaceFunc(DvsML06, Destroy)
  InterfaceFunc(DvsML06, Clone)
;
;  external methods
;
  InterfaceSubr(DvsML06, Main)
;
EndDataSection
;
;===============================================
;  end of  :  clsDvsML06.pbi
;===============================================

_________________
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan


Top
 Profile  
Reply with quote  
 Post subject: Re: What's the most up-to-date OOP framework for PB?
PostPosted: Sat Nov 10, 2012 8:37 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3114
Location: Boston, MA
Same here. Code your own classes.
I just haven't had the need to go full bore with Interfaces and vTables.
I don't deal with COM, so I don't know if this approach will translate there?
For my internal objects, I use Prototypes within Structures. The advantage to me is no pointers to allocate/free memory, no DataSections, etc. But, I do have to pass the Structure for each call to its methods.
Code:
; Syntax using Prototypes in Structures
Define myObj.object_structure
object_new(myObj)
myObj\Method1Of_object(myObj)
myObj\Method2Of_object(myObj)
myObj\Free(myObj)

; Syntax using Interfaces and Virtual Tables in DataSections
Define myObj1.Object_interface = object_new()
myObj\Method1Of_object()
myObj\Method2Of_object()
myObj\Free()

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: What's the most up-to-date OOP framework for PB?
PostPosted: Sat Nov 10, 2012 9:33 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue Apr 24, 2012 5:08 pm
Posts: 542
Location: Ontario, Canada
We arrived at this point via Windows and COM, although we never did do much serious COM programming. So we put something together that was similar to what we were used to, but deliberately kept things simple by avoiding inheritance, overloading, etc.

For large systems, inheritance and the like can create a maintenance nightmare. So instead, we just create an instance of a base class as a property, rather than do the inheritance thing. It works really well and avoids the maintenance complications that can arise if many different classes inherit from the same base class.

The other consideration was that the class code should be easy to read and that we shouldn't need to remember all the funny little syntax rules of PB. We machine-generate all our code, so it was important that the templates and rules were kept as simple as possible. Also, because PB is a single pass compiler, we had to devise a program structure that minimized the use of declare statements. In a large application there might be many thousands of procedures. And finally, our code should be cross-platform.

To accomplish all this we put together about 150 macros to support our classes and program structure. The result is what you see above.

A side effect of our approach is that our code is extremely modular. The macros generate unique names for all the procedures and data elements, so we can create very large applications without having to worry about name conflicts.

_________________
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan


Last edited by BorisTheOld on Sat Nov 10, 2012 9:53 pm, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: What's the most up-to-date OOP framework for PB?
PostPosted: Sat Nov 10, 2012 9:34 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3114
Location: Boston, MA
Here is the same code borrowed from a Demivec example showing 2 approaches to OOP/Class.
I think it shows the Prototypes in Structure method is a bit easier to follow.
Code:
; skywalk, 121110
; Demivec's OOP/Class example using Interface and DataSection of Procedure Addresss
; modified variable names
EnableExplicit
Structure cVector2D
  ; virtual table address for function list
  *vTable
  ; all other object data elements
  x.d
  y.d
  txt$
EndStructure

Procedure cVector2D_New()
  ; Constructor
  Protected *object.cVector2D = AllocateMemory(SizeOf(cVector2D))
  If *object
    ;assign vector table address so object can use the functions in the interface
    *object\vtable = ?vector2D_vtable
    ;assign default values if any
  EndIf
  ProcedureReturn *object ;return objects address
EndProcedure

Procedure cvector2D_Free(*me.cVector2D)
  ; Destructor
  FreeMemory(*me)
  ; the return value is designed to be used like this object = object\Release()
  ProcedureReturn #Null
EndProcedure

Procedure cvector2D_set(*me.cVector2D, x.d, y.d, txt$)
  *me\x = x
  *me\y = y
  *me\txt$ = txt$
EndProcedure

Procedure.d cvector2D_getX(*me.cVector2D)
  Protected.d x = *me\x
  Debug x
  ProcedureReturn x
EndProcedure

Procedure.d cvector2D_getY(*me.cVector2D)
  Protected.d y = *me\y
  Debug y
  ProcedureReturn y
EndProcedure

Procedure.s cvector2D_getTestString(*me.cVector2D)
  Protected txt$ = *me\txt$
  Debug txt$
  ProcedureReturn txt$
EndProcedure

Interface cVector2D_Interface
  ;list all functions for object
  Free()
  set(x.d, y.d, txt$)
  getX.d()
  getY.d()
  getTestString.s()
EndInterface
DataSection
  ; vector2D virtual table
  vector2D_vtable:
  Data.i @cvector2D_Free()
  Data.i @cvector2D_set()
  Data.i @cvector2D_getX()
  Data.i @cvector2D_getY()
  Data.i @cvector2D_getTestString()
EndDataSection
;-{ TEST
Define V1.cVector2D_Interface = cVector2D_new()
If V1 = #Null   ; make sure return value <> #Null to ensure a valid object created
  Debug "Object couldn't be created"
  End
EndIf
V1\set(1.0, -1.0, "String Object Test")
Debug V1\getX()
Debug V1\getY()
Debug V1\getTestString()
Debug V1\Free()
;-} END TEST

Code:
; skywalk, 121110
; Demivec's OOP/Class example modified for Prototypes in Structures
; modified variable names
EnableExplicit
; Prototypes for Vector2D_Object
Prototype   cVector2D_Free(*me)
Prototype   cVector2D_set(*me, x.d, y.d, txt$)
Prototype.d cVector2D_getX(*me)
Prototype.d cVector2D_getY(*me)
Prototype.s cVector2D_getTestString(*me)
Structure cVector2D
  ; Method.Prototype section
  Free.cVector2D_Free
  set.cVector2D_set
  getX.cVector2D_getX
  getY.cVector2D_getY
  getTestString.cVector2D_getTestString
  ; all other object data elements
  x.d
  y.d
  txt$
EndStructure

Procedure cVector2D_Free(*me.cVector2D)
  ; Destructor
  ClearStructure(*me, cVector2D)
EndProcedure

Procedure cvector2D_set(*me.cVector2D, x.d, y.d, txt$)
  *me\x = x
  *me\y = y
  *me\txt$ = txt$
EndProcedure

Procedure.d cvector2D_getX(*me.cVector2D)
  Protected.d x = *me\x
  Debug x
  ProcedureReturn x
EndProcedure

Procedure.d cvector2D_getY(*me.cVector2D)
  Protected.d y = *me\y
  Debug y
  ProcedureReturn y
EndProcedure

Procedure.s cvector2D_getTestString(*me.cVector2D)
  Protected txt$ = *me\txt$
  Debug txt$
  ProcedureReturn txt$
EndProcedure

Procedure cVector2D_New(*me.cVector2D)
  ; Constructor
  ; Define Method/Procedure pointers
  *me\Free            = @cVector2D_Free()
  *me\set             = @cVector2D_set()
  *me\getX            = @cvector2D_getX()
  *me\getY            = @cVector2D_getY()
  *me\getTestString   = @cVector2D_getTestString()
EndProcedure
;-{ TEST
Define V1.cVector2D
cVector2D_New(V1)
If V1 = #Null   ; make sure return value <> #Null to ensure a valid object created
  Debug "Object couldn't be created"
  End
EndIf
V1\set(V1, 1.0, -1.0, "String Object Test")
Debug V1\getX(V1)
Debug V1\getY(V1)
Debug V1\getTestString(V1)
Debug V1\Free(V1)
;-} END TEST

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: What's the most up-to-date OOP framework for PB?
PostPosted: Sat Nov 10, 2012 10:14 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 31, 2005 11:09 pm
Posts: 3693
Location: Italy
skywalk wrote:
I think it shows the Prototypes in Structure method is a bit easier to follow.


Sure but it's (a little) easier to follow for a reason.

For starters, you have to pass the pointer to the object when invoking the method:

Code:
Debug V1\getX(V1)


Looks a little redundant I would say, not dissimilar to simply pass the structure for the "object" data to a regular procedure. And the simplicity in the implementation is lost here in the application.

Another thing, every single instance of your object is bringing with itself the list of pointers to every method, whilst using a vtable you have a single pointer to it for object.

I'm not saying one shouldn't use this approach (I wouldn't though), just wanted to point out those things.

_________________
[ My little PureBasic review ]


Top
 Profile  
Reply with quote  
 Post subject: Re: What's the most up-to-date OOP framework for PB?
PostPosted: Sat Nov 10, 2012 10:48 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3114
Location: Boston, MA
Yes luis, I already mentioned the redundant passing of the structure. :?
What do you mean by?
luis wrote:
the simplicity in the implementation is lost here in the application.

luis wrote:
every single instance of your object is bringing with itself the list of pointers to every method, whilst using a vtable you have a single pointer to it for object.

Is this a significant performance hit? I mean its only a few extra integers stored in the structure? If the Object has hundreds more, then I might agree. But I have not created classes of that size or scope. Anything that large has been confined to procedural libraries.

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: What's the most up-to-date OOP framework for PB?
PostPosted: Sat Nov 10, 2012 11:06 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 31, 2005 11:09 pm
Posts: 3693
Location: Italy
skywalk wrote:
What do you mean by?
luis wrote:
the simplicity in the implementation is lost here in the application.


I mean: the preparation of the "objects" can be maybe easier, but if you have to pass the object every time you invoke the method the tradeoff is you have redundancy when you are using the objects. Something like V1\getX(V1) is a deal breaker for me. :)

skywalk wrote:
Is this a significant performance hit?


Not at all. Only a larger footprint, something that can be avoided with another approach, that's all. Generally the idea is to avoid redundancy when possible (unless it's for integrity reasons).

_________________
[ My little PureBasic review ]


Top
 Profile  
Reply with quote  
 Post subject: Re: What's the most up-to-date OOP framework for PB?
PostPosted: Sat Nov 10, 2012 11:08 pm 
Offline
Addict
Addict

Joined: Thu Nov 01, 2007 5:37 pm
Posts: 1981
Location: Germany
Thanks for all your input!

I just learned the basic OOP concepts and found them to be pretty useful for making code (of larger projects) easier to understand. It seems that there are a lot of different approaches which all share the same idea of putting some of the functionality into PureBasic depending on what someone just needs.
Unfortunately the overwhelming amount of suggestions are over my head and make it hard for me to get a proper starting point for a general solution. Yes I get it, unless it is officially added there is no such thing, but I hope you understand what I mean.

Where does a OOP beginner start implementing it in PureBasic? Prototypes, interfaces, structures, vtables, a little pointer here and some others there..?

I'd like to have classes with public/private fields, public/private methods and de-/contructors:
- From what I've seen so far I guess methods are the easiest thing to implement.
- Fields might be harder but possible as well.
- Then for the constructors I'll probably need some macro tricks, am I right?!
- I think the private/public thing might be impossible without a preprocessor.

_________________
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!


Top
 Profile  
Reply with quote  
 Post subject: Re: What's the most up-to-date OOP framework for PB?
PostPosted: Sat Nov 10, 2012 11:41 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 31, 2005 11:09 pm
Posts: 3693
Location: Italy
c4s wrote:
- I think the private/public thing might be impossible without a preprocessor.


A private method is simply a procedure in the same include of the class implementation.

If a public method Hello() is implemented for the class Test instantiated as T1 and invoked as T1\Hello() probably in the include it will be defined as the procedure Test_Hello().

The private method Goodbye() will be defined as Test_Goodbye() and not present in the interface, so only the the class will be able to call it.

A private field is something for which you haven't set a Get(), Set() public method.

Well, I'll post my include too in the end, so you can see what I mean in my context. I'll write a sample but without private stuff since I want to keep it simple.

You can apply what I said above to it if you like to do that.

_________________
[ My little PureBasic review ]


Last edited by luis on Sun Nov 11, 2012 12:28 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye