that sounds like some good news
Hi all,
in next thinBasic version (I'm almost ready) there will be a little more OOPification of standard ThinBasic TYPEs.
As you may already aware, you can define Functions inside TYPEs more or less like having methods in classes for languages supporting OOP.
The new features I've added will be:
- type extension (similar to class inheritance)
You can create a TYPE that Extends another TYPE functionality- a kind of functions polymorphic when same function name is defined in derived types
Extended TYPEs will inherit base TYPE elements and functions. Base Functions can be redefined in Extended type
In case you would like to test new features:
http://www.thinbasic.biz/projects/th...c_1.9.12.0.zip
I still need to develop error checking so you might experience some GPF for those new features if you do not follow the rules but it should work.
Example in \thinBasic\SampleScripts\OOP\Example_030_Extends.tbasic
A little example count more than 1000 words:
Uses "console" '----------------------------------------------- '----------------------------------------------- Type t2D x As Long y As Long Init As Function ToString As Function End Type Function t2D.Init(ByVal x As Long, ByVal y As Long) As Long Me.X = x Me.Y = y End Function Function t2D.ToString() As String Function = "(" & Me.x & "," & Me.Y & ")" End Function '----------------------------------------------- ' t3D extends t2D type adding a new element/property ' and redefining 2 type functions '----------------------------------------------- Type t3D Extends t2d Z As Long Init As Function ToString As Function End Type Function t3D.Init(ByVal x As Long, ByVal y As Long, ByVal z As Long) As Long Me.X = x Me.Y = y Me.Z = z End Function Function t3D.ToString(Optional ByVal sSep As String) As String If sSep = "" Then sSep = "," Function = "(" & Me.x & sSep & Me.Y & sSep & Me.z & ")" End Function '----------------------------------------------- '----------------------------------------------- Dim p3D As t3D Dim p2D As t2D p3D.Init(10, 20, 30) p2D.Init(100, 200) PrintL "SizeOf p2D =", SizeOf(p2D) PrintL "p2D ToString =", p2D.ToString PrintL PrintL "SizeOf p3D =", SizeOf(p3D) PrintL "p3D ToString =", p3D.ToString("-") PrintL "----------------------------" PrintL "All done, press a key to end" WaitKey
Last edited by ErosOlmi; 16-03-2014 at 14:48.
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
that sounds like some good news
I think there are missing some Forum-sections as beta-testing and support
This is good news!
The OOPification is great, code units I design at work are all encapsulated in "super types".
I like the ME., it is shorter than THIS. and much more... personal
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Just to make sure,
ME <> THIS !
ME indicates an element of some TYPE inside a type-function, THIS indicates a member of a CLASS inside a class-method. Just so sorry the other languages don't have to care about that difference since none of them has functional types as tB has them
@Eros,
for the "init" - which is a certainly often used function to any type - (guess I suggested something similar already long time ago...) - how about some implemented default-Init-Function for all Type's?
Somewhat alike this:
so pretty much the function takes all subsets (like X as Long, Y as Long...) of the type-declaration as Optional function-parameters.Type t_2D X as Long Y as Long End Type ' there's no "Init as Function" ' simple variables as Long in Type... ' the built-in Init-function to the Type would work somewhat alike this: Function t_2D.Init(Optional Byval X as Long, Optional Byval Y as Long) As DWord ' assume there's something alike "Local Me As t_2D At VarPtr(FunctionCalledFrom)" Me.X = X Me.Y = Y Function = Varptr(Me) ' could return Me-VarPointer for further usage..., <>0 means success... End Function ' I (user) just would call it then Dim myPoint1 as t_2D myPoint1.Init(12,34) ' so X will be 12, Y 34 then 'or Dim myPoint2 as t_2D myPoint2.Init() ' here X and Y are 0...
Now extend this to types with other types embedded
how would the "built-in Init-function to all types" take my parameters here?Type t_2D ' the embedded type X as Long Y as Long End Type Type t_Maintype A As Byte B As Byte Pos as t_2D ' now this is no "simple variable"... C As Byte End Type ' neither Init here, because built-in... Dim Example(123) as t_Maintype ' I could call it like this: Local myOverlay As t_Maintype At Example(42).Init(1,2, MKL$(45, 67), 3 )
Perhaps change from "Init" to "Set" or "Be" ?
Last edited by ReneMiner; 14-03-2014 at 10:09.
I think there are missing some Forum-sections as beta-testing and support
Rene,
I was so happy to see you posting again ... ... but after this post ... not so happy
I will think about it.
I already have some nice additional implementations.
Ciao
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
-oh I was only absent because I was hooked to some excessive "game-testing" for a while (as excessive as I use to code at other times) since I have no real idea what useful script to write next...
Did the "Like"-expression-developement get any further in the meantime so it will allow UDTs soon?
I think there are missing some Forum-sections as beta-testing and support
and... - forget about the init/set/be- we still can use
With Example(42) ...
And to make sure I've understood:
I need to re-write the functions and re-introduce them for the extended type (t3d) only if I don't want it to use the same function as the base-type (t2D) but to be "user-defined"?
Last edited by ReneMiner; 14-03-2014 at 19:48.
I think there are missing some Forum-sections as beta-testing and support
Yes
Extended TYPE will get all the items (properties) and functions (methods) of the base TYPE
If you create in the extended TYPE a function with the same name of the base Type, in that case the new function will win.
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Hi Eros,
Really nice implementation. You don't even need to use the 'class' word!
My thoughts on inheritance in general:
Inheritance turns out to be less useful as a major concept of OOP than was originally conceived. Petr mentioned the term 'Supertypes' which I take to mean a collection of object types which can be totally different but have the same interfaces, same function names. For example you could have diverse objects like text, sounds, textures, backgrounds, 3d objects which could all have create() set(), get() render() and delete() methods in common but may be structurally unrelated on the inside.
Last edited by Charles Pegge; 15-03-2014 at 09:21.
Hi Charles!,
I actually use the term supertypes for any type with functions currently. Your idea of interfaces is good one, and could be pushed further syntactically (Like TYPE GameObject Implements IRenderable, ITransformable )
Hi Rene!,
great to see you around again!
Traditionally, BASIC languages use ME for the same thing as THIS, just have a look at VB.NET. I don't differentiate between supertype and class, they are both tools for achieving object oriented design.Just to make sure,
ME <> THIS !
ME indicates an element of some TYPE inside a type-function, THIS indicates a member of a CLASS inside a class-method.
Petr
Last edited by Petr Schreiber; 15-03-2014 at 08:51.
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Bookmarks