Multiple extends

BlitzMax Forums/BlitzMax Programming/Multiple extends

nawi(Posted 2007) [#1]
Is it possible to create two types (if not, will it ever be included in BlitzMax?), lets say Type Point and Type Angle, then create the third type called Entity and extend both of those? It would create neat code but doesn't seem to possible :/.


Dreamora(Posted 2007) [#2]
No this is not possible. BM only supports single inheritance.

But what you can do is extend it from one and hold the other type as field and use both for example. Or doing meta inheritance using the reflection features. (I am thinking about a possibility of how to missuse that to give BM Interface capabilities like JAVA has them so you can extend from one class but implement different interfaces)


Brucey(Posted 2007) [#3]
Meta Inheritance. Cool ;-)

I could really do with Interfaces... surely it can't be that hard to implement?? Mark! :-p


Scaremonger(Posted 2008) [#4]
Not really multiple inheritance, but I've used this before to share functions between types that are not related.

Local myvar:Tmytype = New Tmytype

Print myvar.Capital( "blitzmax" ) 
Print myvar.Length( "blitzmax" )
Print myvar.Reverse( "blitzmax" ) 

Type TParent
	Method Capital$( str$ ) 
	Return Upper( str ) 
	End Method
End Type

Type Tmytype Extends TParent
	'# Multiple inheritance
	Field reverse$(str$) = IInterface.Reverse
	'#
	Method Length$( str$ ) 
	Return "Length: " + Len(str)
	End Method
End Type

Type Iinterface
	Function reverse$( str$ ) 
	Local result$
		For Local n% = Len(str) To 1 Step - 1
			result:+ str[n-1..n]
		Next
	Return result
	End Function
End Type