I grasp at the conceptual level what you want to do, but I think there are a couple of issues in your code example. Also, you need to decide if you want to truly emulate inheritance, or just get the job done in an easy way.
First, in your example, Property must be Get, Let, or Set. I think you need this:
Property Set o() as Selenium.WebDriver
Set o = WebDr
End Property
Secondly, allowing the caller to retrieve the original object breaks the abstraction you are trying to create. That can work but exposes to the caller that you have the original object, plus a bunch of stuff you have added. Plus, from the caller's standpoint, there is no guarantee that operating on that object will continue to be reflected in the extended object. To truly replicate inheritance, you would have to code every property and method of the original, and not allow access to the underlying object. Otherwise the caller has to know when it's dealing with your extended class vs. the original class. If you hide the original object, then the caller does not have to go through the extra step of retrieving the original object, and operating on that. However, this requires writing a method and property for every method and property in the original class (which normally inheritance would do for you under the covers).
Property Get OriginalProperty()
OriginalProperty = WebDr.OriginalProperty
End Property
Property Set OriginalProperty(NewOriginalPropertyValue) As Long
WebDr.OriginalProperty = NewOriginalPropertyValue
End Property
Sub OriginalMethod(SomeArgument As String)
WebDr.OriginalMethod(SomeArgument)
End Sub
Further, as to your example, it is not clear how you can reference a non-existent method or property in the WebDr object:
Sub myExampleMethod1()
WebDr.CustomizedSomething...
End Sub
I think you would need something like this to create a new method, which references available methods/properties:
Sub ForcePositive() ' Custom method (illustrates CustomedSomething with a concrete example)
If WebDr.Property1 < 0 ' I do not have a spec for this class so I don't know the properties, Property1 is fake
WebDr.Property1 = 0
End If
End Sub
or something like this which creates a new property:
Private localNewProperty As Long ' declare at the top
Property Get NewProperty() As Long
NewProperty = localNewProperty
End Property
Property Let NewProperty(NewPropertyNewValue As Long)
localNewProperty = MyNewPropertyNewValue
End Property
Bookmarks