Types Inheritance - Naming problem

BlitzMax Forums/BlitzMax Programming/Types Inheritance - Naming problem

PetBom(Posted 2005) [#1]
Maybe I'm beeing completely daft, but I have a problem when I'm tying to create an nice way to express iherited classes. Look at this example. It is a type called Foo that contains a type called Bar that is accessable trough Foo.Bar


Strict

Type Foo

	Field Bar:Bar = New Bar

End Type

Type Bar
	
	Field SomeValue:Int = 1

End Type


Global myFoo:Foo = New Foo

DebugLog myFoo.Bar.SomeValue
This example does not work. The problem occurs when I try to assign the "Bar" Field in the "Foo" type. There is a name collision an with the field having the same name as the type that I'm trying to create. If we adjust the example like this...:


Strict

Type Foo

	Field BarName:Bar = New Bar

End Type

Type Bar
	
	Field SomeValue:Int = 1

End Type


Global myFoo:Foo = New Foo

DebugLog myFoo.BarName.SomeValue
...everything works fine. But the point is that I want the Field name to be same as the type name because it makes the syntax for retriving "SomeValue" more logical:

myFoo.Bar.SomeValue


Maybe it is my method of implementing this type of inheritance that is comletely wrong.

Ideas anyone?


Dreamora(Posted 2005) [#2]
This is no inheritance.

Inheritance would be with

type foo

end type
type bar extends foo

end type


PetBom(Posted 2005) [#3]
Well, yeah you are right. It's not inheritance in the traditional sense. What should I call it then...Object inheritance?


Who was John Galt?(Posted 2005) [#4]
That's just the way max is. Stick a T in front of your type names. Bar:Tbar=new Tbar. Not the answer you were hoping for, but it's an answer.


Dreamora(Posted 2005) [#5]
It has nothing to do with inheritance, so no kind of inheritance. It is a simple object reference.


Robert(Posted 2005) [#6]
I simply place an underscore in front of all field variables which prevents naming conflicts.

Type Foo
    Field _bar:Bar
End Type



Tibit(Posted 2005) [#7]
What Falken said, and it would look like this:
Strict

Type TFoo

	Field Bar:TBar = New TBar

End Type

Type TBar
	
	Field SomeValue:Int = 1

End Type


Global Foo:TFoo = New TFoo

DebugLog Foo.Bar.SomeValue



PetBom(Posted 2005) [#8]
@Dreamora
Object reference! Thank you! That was the word I was looking for.

@Falken, Robert, Wave.
Yeah, but what you are saying is what I already did in the second example in the original post. So the question is not how to solve it. I know that. The point Í'm making is that a field or variable name can not be the same as the name of a type.


FlameDuck(Posted 2005) [#9]
What should I call it then...Object inheritance?
Actually the correct buzzword is a composite object. (As in an object that is composed of others).