Base Class - Super Constructor
BlitzMax Forums/BlitzMax Beginners Area/Base Class - Super Constructor| 
 | ||
| Take this as my base class: Type ExampleBaseClass Function Construct:ExampleBaseClass(ob:SomeObject) ' Note: do I need to make a new object of the base class? Local retObject:ExampleBaseClass = new ExampleBaseClass ' Do code here to set-up base class return retObject End Function End Type Type Stuff Extends ExampleBaseClass Function Construct:Stuff(ob:SomeObject) ' Note: how is the super constructor called? How do I give it the object it needs? Local retObject:Stuff = new Stuff ' Continue code, with base class set up return retObject End Function End Type I included 2 notes in the above code that have the questions I need answered. Edit this code as needed, there is not much documentation on how BlitzMax does this. | 
| 
 | ||
|   how is the super constructor called? How do I give it the object it needs?  You use Methods instead... it's much more flexible. Type ExampleBaseClass Method Construct:ExampleBaseClass(ob:SomeObject) ' Do code here to set-up base class Return Self End Method End Type Type Stuff Extends ExampleBaseClass Method Construct:Stuff(ob:SomeObject) ' Continue code, with base class set up Super.Construct(ob) Return Self End Method End Type ' to create a new Stuff : Local myStuff:Stuff = New Stuff.Construct(....) | 
| 
 | ||
| Works great, and I never thought of using a method for a constructor... my old way[Pseudo Code]: 
private varInt
------------------------------------------
function constructor(intValue) {
    declare object = new Object
    object.varInt = intValue
    return object
}
and then i continue with OOP with the object, but I like your 'method' a lot better! Thanks! rep+1 ;) |