No, extension is not broken, that's the amazing point!
I think the example i was providing is not really showing what I mean:
Code for module blide.test1 (blitzmax/mod/blide.mod/test1.mod/test1.bmx)
And then, the sample code for MyFile.bmx:
In fact, in this example, the class LineConcat has a 'friend private' fields X and Y. Those fields are not accesible outside the module becouse they're based on a private type, but the class is still extensible outside the module. they are not real 'private' obviously, but they work a lot like visual basic .net 'friend' atributes, so they are only accesible inside the module. Obviously extending the class outside the module won't give you access to this sort of private fields and you will still have to call super.whatever to let the base class use them internally, but isn't this how friend fields are suposed to work? Am I missing something? I know it is not elegant, and maybe a litle bit heretic, but taking in consideration we don't have public and private at field or method level...
Let me know what you think, please.
I think the example i was providing is not really showing what I mean:
Code for module blide.test1 (blitzmax/mod/blide.mod/test1.mod/test1.bmx)
SuperStrict Import brl.max2d Type LineConcat Field _private:TLConcatPrivate = New TLConcatPrivate Method DrawLine(x:Int, y:Int) _private.DrawLine(Self, x, y) End Method Method SetPos(x:Int, y:Int) _private.X = x _private.Y = y End Method End Type Private Type TLConcatPrivate Field X:Int Field Y:Int Method DrawLine(LC:LineConcat, x:Int, y:Int) brl.max2d.DrawLine(x, y, Self.X, Self.Y) Self.X = x Self.Y = y End Method End Type Public
And then, the sample code for MyFile.bmx:
SuperStrict Import blide.test1 Graphics(800, 600) Cls Flip Local P:LineConcat = New LineConcat p.SetPos(Rand(0, 800), Rand(0, 600)) While Not KeyHit(KEY_ESCAPE) p.DrawLine(Rand(0, 800), Rand(0, 600)) SetColor 0, 0, 0 DrawText("Using base class. (PRESS ESC)", 1, 1) SetColor 255, 255, 255 DrawText("Using base class. (PRESS ESC)", 0, 0) Flip() Wend Cls Type LineConcatExtended Extends LineConcat Method DrawLine(x:Int, y:Int) SetColor(Rnd(0, 255), Rnd(0, 255), Rnd(0, 255)) Local F:Float = GetLineWidth() SetLineWidth (7) Super.DrawLine(x, y) SetLineWidth(F) End Method End Type Local p2:LineConcatExtended = New LineConcatExtended While Not KeyHit(KEY_ESCAPE) p2.DrawLine(Rand(0, 800), Rand(0, 600)) SetColor 0, 0, 0 DrawText("Using extended class. (PRESS ESC)", 1, 1) SetColor 255, 255, 255 DrawText("Using extended class. (PRESS ESC)", 0, 0) Flip() Wend
In fact, in this example, the class LineConcat has a 'friend private' fields X and Y. Those fields are not accesible outside the module becouse they're based on a private type, but the class is still extensible outside the module. they are not real 'private' obviously, but they work a lot like visual basic .net 'friend' atributes, so they are only accesible inside the module. Obviously extending the class outside the module won't give you access to this sort of private fields and you will still have to call super.whatever to let the base class use them internally, but isn't this how friend fields are suposed to work? Am I missing something? I know it is not elegant, and maybe a litle bit heretic, but taking in consideration we don't have public and private at field or method level...
Let me know what you think, please.