Navigation:  ThinBASIC Language > Data types and variables > TYPE (ord UDT User Defined Types) > UDT (User Defined Types) >

Extending existing UDT

Previous pageReturn to chapter overviewNext page

 

Extending existing UDT

 

Once designing a new type, you don't have to start from a scratch.

 

Imagine our Point2D type, defined in the previous chapters.

 

It has two members, x and y.

 

TYPE Point2D
  x AS SINGLE
  y AS SINGLE
END TYPE

 

Once you will need to create 3D point, the obvious approach would be to do it this way:

 

TYPE Point3D
  x AS SINGLE
  y AS SINGLE
  z AS SINGLE
END TYPE

 

The advantage of this copy-paste approach is that it is straightforward, but once you would add something to Point2D, it would need to be promoted to Point3D manually.

 

Let's have a look at two different approaches to create new type based on existing one.