It is currently Wed Aug 21, 2019 6:10 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Precompilator oop
PostPosted: Tue Dec 26, 2017 1:50 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Jun 13, 2014 9:38 am
Posts: 131
Hello everybody,

I like very much the oop programming style, but pureBasic have not this functionality. But we can define une lite software which is called before the compilation.

It try to make it at this time, and i show to you the result of a small test.

Now i don't share this software because it's not quite advanced, i have lot of work for make that. But i just show to you it is possible.



Image

code of oop layer
Code:
Class Car
  private string name
  private int id
  public Method  Car(string name,int id)
    this.name = name
    this.id = id
  EndMethod
  public Method void teste(string name)
    Debug name
  EndMethod
  public Method string getName()
    return this.name
  EndMethod
EndClass
Class FleetCar
  private string name
  public Method FleetCar(string name)
    this.name = name
  EndMethod
EndClass
Global Car myCar = new Car("volvo",1)

myCar\teste("ok")
Debug myCar\getName()


Generated code by the precompilation
Code:
DeclareModule __OOP_INTERFACES
Interface Car

getName.s()
teste(name.s)

EndInterface
Interface FleetCar


EndInterface

EndDeclareModule
Module __OOP_INTERFACES
EndModule
DeclareModule _Car
Structure _struct
*methods
id.l
name.s
EndStructure

Declare new(name.s,id)
EndDeclareModule
Module _Car
Procedure new(name.s,id)
Protected *this._struct = AllocateStructure(_struct)
With *this
\methods = ?METHODS
    \name = name
    \id = id
ProcedureReturn *this
EndWith
EndProcedure
Procedure.s getName(*this._struct)
With *this
    procedureReturn \name

EndWith
EndProcedure
Procedure teste(*this._struct,name.s)
With *this
    Debug name

EndWith
EndProcedure

DataSection
METHODS:

Data.i @getName()
Data.i @teste()
EndDataSection
EndModule
DeclareModule _FleetCar
Structure _struct
*methods
name.s
EndStructure

Declare new(name.s)
EndDeclareModule
Module _FleetCar
Procedure new(name.s)
Protected *this._struct = AllocateStructure(_struct)
With *this
\methods = ?METHODS
    \name = name
ProcedureReturn *this
EndWith
EndProcedure

DataSection
METHODS:

EndDataSection
EndModule
Global myCar.__OOP_INTERFACES::Car = _Car::new("volvo",1)
myCar\teste("ok")
Debug myCar\getName()

_________________
Use Pb 5.60 lst and Windows 10

my mother-language isn't english, in advance excuse my mistakes.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 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