inheritance and encapsulation

BlitzMax Forums/BlitzMax Programming/inheritance and encapsulation

Cruis.In(Posted 2013) [#1]
Hey there, some weird behavior in my program recently has led me to wonder what wrong assumptions about OO I am making.

If I have Tcar and I want to make separate models like TForde, THonda etc... all should extend Tcar without issues correct?

If I have Tcar and I make TTruck extend Tcar, now that Ttruck obviously has some methods etc that Tcar does not have, can i then without issues create a TDodge Extending Ttruck?

initially tcar has properties and methods used by ttruck hence the extension. But ttruck evolved to be more than tcar, so any issues with extending tDodge off of TTruck?


Brucey(Posted 2013) [#2]
Don't Dodge make cars too? :-p

You can happily subclass TTruck for all truck types.

Presumably you could also have a TVehicle class of which TCar and TMotorbike are subclasses of.


Cruis.In(Posted 2013) [#3]
And the fields in Tcar, should be unaffected, if a modification is made to the fields in THonda.

Because the whole point to extending is so you don't have to list out those fields again.

What if they were globals?

Tcar has 4 globals

and you create THonda extends Tcar

if i change globals in thonda, would they change in Tcar? the globals have not been re-typed in Thonda. since they inherited them from Tcar.


Brucey(Posted 2013) [#4]
Globals? Tut tut tut…

Globals are globals… you don't even need an Object to change the values.

TCar.someGlobal = 10

THonda.someGlobal = 20

It's the same data you are changing.


Cruis.In(Posted 2013) [#5]
figured. hehehe

But you do need globals, just in this case, i'd have to initialize new ones and modify them as needed with the particular object. Like for list. The updateall function can't see a list if its a field.

I was applying that logic to it, but in this case it wasn't needed, created an object for the three different things, switched to fields and my object orientation expectations resumed. :)

See I had never used globals before for anything but a list, hence why I hadn't come across whether they were global only to type.

thanks


Brucey(Posted 2013) [#6]
The updateall function can't see a list if its a field

Well, that all depends on your design, I guess.