Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA: is there something like Abstract Class?

I'm using an interface to ensure some similar classes implements some mandatory methods (subs/functions).

Example:

  • interface I1 declares M1 and M2 methods
  • C1 and C2 implement I1, and have their own versions for M1 and M2.

C1 and C2 also need methods that are exactly the same, for example methods SM1 and SM2.

To avoid repeating SM1 and SM2 I'd like to define an abstract class AC:

  • implementing I1
  • defining SM1 and SM2.

which would be extended by C1 and C2

This solution is indeed possible in Java, but I don't find any documentation for doing the same in VBA. (VB.Net seems to allow abstract classes using keyword MustInherit.)

Any confirmation it is possible or not in VBA?

like image 667
mins Avatar asked Jan 19 '14 17:01

mins


1 Answers

There is no inheritance in VBA.

You can define an interface and you can implement it in a class by using the Implements keyword. But if you want shared functionality pre-implemented by a base class, you have to use the copy-paste approach.

Related reading:
How to use the Implements in Excel VBA
How to use comparison methods between class object modules in VBA in a similar manner as VB.NET?

like image 108
GSerg Avatar answered Oct 04 '22 06:10

GSerg