Overiding methods help needed

BlitzMax Forums/BlitzMax Beginners Area/Overiding methods help needed

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I'm not sure if this is a good way to do it but I just had this idea of a way in which you could use overridden methods.

You have a base vehicle type which is abstract. That means you cannot make an actual vehicle - it is a template.

A vehicle variable can accept any type that extends from it. Here we have smallship and largeship. Each ship has a different upgrade method, and you would put any actions unique to a type of ship in its own type. Only common actions are placed in vehicle.

Type vehicle Abstract
   Method upgrade:vehicle() Abstract
   Method move()
      'assuming all vehicles move in the same way put common code in this type
   End Method
End Type

Type smallship Extends vehicle
   Method upgrade:vehicle()
      Local newvehicle:vehicle = New largeship
      Return newvehicle
   End Method
End Type

Type largeship Extends vehicle
   Method upgrade:vehicle()
      Local newvehicle:vehicle = New nextship
      Return newvehicle
   End Method
End Type


'''''''''

Local player:vehicle = New smallship
player = player.upgrade() 'now a bigship