Class Interfaces

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,924
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
This video shows how to use Class Interfaces:

https://www.youtube.com/watch?v=3bO50gHRndA

The restriction I find with Interfaces is every class that implements the Interface class must adhere to its rules.

Instead, why not do this?

Code:
Sub Test()

    Dim obj As Object
   
    Dim i As Long
   
    For i = 1 To 2
   
        If i = 1 Then
       
            Set obj = New Class1
       
        Else
           
            Set obj = New Class2
       
        End If
       
        Call obj.PrintMsg
       
    Next i
   
End Sub

Class1:

Code:
Sub PrintMsg()

    Debug.Print 1
   
End Sub

and Class2:

Code:
Sub PrintMsg()

    Debug.Print 2
   
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
The restriction I find with Interfaces is every class that implements the Interface class must adhere to its rules.
That is the entire point of interfaces...
 
Upvote 0
That is the entire point of interfaces...
One of the benefits of using classes is reuseability.

So if changes are required, it makes life easier.

But with class interfaces, if the interface needs to change, all other classes that implements it must also change.

Isn't that going to cause a lot of pain?
 
Upvote 0

Forum statistics

Threads
1,223,922
Messages
6,175,384
Members
452,639
Latest member
RMH2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top