Page 4 of 4

Re: Module BaseClass (Module as Object)

Posted: Tue Mar 03, 2020 7:05 pm
by mk-soft
Recreated the baseclass.zip

Will probably switch off the AFP support for macOS, then no strange folders and files will be created.
You can also connect to an SMB server under macOS.

Re: Module BaseClass (Module as Object)

Posted: Tue Mar 03, 2020 8:26 pm
by Kurzer
:shock: Something went wrong!

Example4 and Example7 are broken in your zip archive.
The files are smaller than 201 bytes and 95% of the code is missing.

Also the separate, non compressed files on your webspace are broken in the same manner.

Re: Module BaseClass (Module as Object)

Posted: Tue Mar 03, 2020 8:36 pm
by mk-soft
Its empty code... 8)

Re: Module BaseClass (Module as Object)

Posted: Tue Mar 03, 2020 8:43 pm
by Kurzer
Indeed, but why you include code like this into the zip archive?

Code: Select all

;-TOP

; Example 4 - v1.13

IncludeFile "Modul_BaseClassSmall.pb"
But maybe I didn't get the joke. Sometimes I feel a little bit autistic :oops:

Re: Module BaseClass (Module as Object)

Posted: Tue Mar 03, 2020 8:59 pm
by mk-soft
These were examples that no longer worked with the small version.

Sorry :!:

These will be filled in sometime

Re: Module BaseClass (Module as Object)

Posted: Mon Apr 13, 2020 2:24 pm
by mk-soft
1.
I thought about how to separate public and private attributes.
To do this you have to create memory and store the pointer for the private attributes in the object. There is a new entry in the BaseSystem (*This\System\Private) and a fixed structure name (sPrivate)

2.
There are also class attributes (package attributes) that are valid for all objects in the class.
If necessary, you must create memory for them and store the pointer for the package attributes in the class.
There is a new entry for this in the class. (*This\System\Class\Package) and a fixed structure name (sPackage)
For initializing the package attributes there is a new macro (InitPackage) which requests the memory and allocates it to the class.

The class methods are programmed in the same way as object methods. But you can consider to program the class methods first and then inherit them to the object.

Here is a simple example.

Code: Select all

; Removed

Re: Module BaseClass (Module as Object)

Posted: Tue Apr 14, 2020 10:05 am
by mk-soft
Update v1.18
- Added macros for private attributes :wink:

* AllocatePrivate(...)
* FreePrivate(...)
* GetPrivate(...)

Re: Module BaseClass (Module as Object)

Posted: Tue Apr 14, 2020 6:22 pm
by Kurzer
mk-soft,
many thanks for the continuous development of your baseclass. And especially that it still gets along completely without precompiler. Image

Greetings
Kurzer

Re: Module BaseClass (Module as Object)

Posted: Sat Apr 18, 2020 4:16 pm
by mk-soft
Update v1.19
- Bugfix private attributes for inheritance of objects.

Update v1.20
- Optimize Private (Initializations only if necessary)

Re: Module BaseClass (Module as Object)

Posted: Thu May 28, 2020 11:51 am
by mk-soft
Update v1.21
- Removed Private Macros and Pointer

I didn't like the solution for Private Attributes and it was too complex and made it confusing.
So I removed this from the BaseClass.
Most of the time it is also better to inherit the attributes to make it easier to access

There are better methods to solve this if needed. For example with a map.

Code: Select all

;-TOP

; Example 4 - v1.21
; - Public and Private Attributes
; - Package Attributes

IncludeFile "Modul_BaseClassSmall.pb"

DeclareModule Cars
  
  ; Public Methods
  Interface iCars Extends BaseClass::iBaseClass
    getType.s()
    setType.s(Type.s)
    getColor.s()
    setColor(Color.s)
    getWheels()
    setWheels(Count)
    getDriver.s()
    setDriver(Driver.s)
    Count()
  EndInterface
  
  ; Public Attributes
  Structure sCars Extends BaseClass::sBaseClass
    Type.s
    Color.s
    Wheels.i
  EndStructure
  
  ; Create Object
  Declare New()
  
EndDeclareModule

Module Cars
  
  UseModule BaseClass
  
  NewClass(iCars)
  
  ; Define Package Attributes
  Structure sPackage
    Count.i
  EndStructure
  
  ; Init Package Attributes
  InitPackage()
  
  ; Define Private Attributes
  Structure sPrivate
    Driver.s
  EndStructure
  
  Global NewMap Private.sPrivate()
  
  ; ----
  
  ;- Private Methods
  
  Procedure Init(*This.sCars)
    ; Allocate memory for private attributes
    AddMapElement(Private(), Str(*This))
    ; Inc class counter
    *This\System\Class\Package\Count + 1
  EndProcedure : AsInitializeObject(Init)
  
  Procedure Dispose(*This.sCars)
    ; Free memory for private attributes
    DeleteMapElement(Private(), Str(*This))
    ; Dec class counter
    *This\System\Class\Package\Count - 1
  EndProcedure : AsDisposeObject(Dispose)
  
  ; ----
  
  ;- Public Object Methods
  
  Procedure.s getType(*This.sCars)
    ProcedureReturn *This\Type
  EndProcedure : AsMethode(getType)
  
  Procedure setType(*This.sCars, Type.s)
    *This\Type = Type
  EndProcedure : AsMethode(setType)
  
  ; ----
  
  Procedure.s getColor(*This.sCars)
    ProcedureReturn *This\Color
  EndProcedure : AsMethode(getColor)
  
  Procedure setColor(*This.sCars, Color.s)
    *This\Color = Color
  EndProcedure : AsMethode(setColor)
  
  ; ----
  
  Procedure getWheels(*This.sCars)
    ProcedureReturn *This\Wheels
  EndProcedure : AsMethode(getWheels)
  
  Procedure setWheels(*This.sCars, Wheels)
    *This\Wheels = Wheels
  EndProcedure : AsMethode(setWheels)
  
  ; ----
  
  Procedure.s getDriver(*This.sCars)
    ProcedureReturn Private(Str(*this))\Driver
  EndProcedure : AsMethode(getDriver)
  
  Procedure setDriver(*This.sCars, Driver.s)
    Private(Str(*This))\Driver = Driver
  EndProcedure : AsMethode(setDriver)
  
  ; ----
  
  ;- Public Class Method
  Procedure Count(*This.sCars)
    Protected *Package.sPackage = GetPackage()
    ProcedureReturn *Package\Count
  EndProcedure : AsMethode(Count)
  
  ; ----
  
  Procedure New()
    InitObject(sCars)
  EndProcedure
  
  CheckInterface()
  
EndModule

; ****

Define.Cars::iCars obj1, obj2, obj3

obj1 = Cars::New()
obj1\setType("Mercedes")
obj1\setColor("Green")
obj1\setWheels(4)
obj1\setDriver("Michael")

obj2 = Cars::New()
obj2\setType("Mercedes")
obj2\setColor("Gray")
obj2\setWheels(4)
obj2\setDriver("Tom")

obj3 = Cars::New()
obj3\setType("Ford")
obj3\setColor("Blue")
obj3\setWheels(4)
obj3\setDriver("Jerry")

Debug "Class Package - Count = " + obj1\Count()
obj2\Release()
Debug "Class Package - Count = " + obj1\Count()
obj3\Release()
Debug "Class Package - Count = " + obj1\Count()

obj3 = Cars::New()
obj3\setType("Ford")
obj3\setColor("Blue")
obj3\setWheels(4)
obj3\setDriver("Jerry")
Debug "Class Package - Count = " + obj1\Count()

Debug obj1\getType() + " - " + obj1\getDriver()
Debug obj3\getType() + " - " + obj3\getDriver()
[/size]