• 0

Type Inheritance in vb6


Question

I've read that it's impossible, but i'm sure the problem i'm facing now has a simple solution.

How could i achieve a sort of "inheritance" in the following type definitions? (written in a .bas module)

I can't imagine something simple as this can't be achieved in VB6 :o

Public Type Dim2D
	width As Integer
	height As Integer
End Type

Public Type Coord2D
	left As Integer
	top As Integer
End Type

Public Type Rectangle
	'inherit Coord2D
	'inherit Dim2D
End Type

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

I don't know VB that well, but what I will say is that www.xtremevbtalk.com would be a good place to ask this question.

Link to comment
Share on other sites

  • 0

You cannot inherit implementation in VB6, you can only inherit interface, i.e. public methods. http://msdn.microsoft.com/en-us/library/yet634fk(VS.80).aspx

You can achieve implementation inheritance using composition. That is, class Derived contains a member of type Base. Both Base and Derived can inherit from a common interface so they can be used polymorphically.

This technique is widely used even in language supporting implementation inheritance, because it reduces coupling between classes.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.