Note sure if 'wrapping' is the right terminology. Essentially, I'm building a class that has another class as a private member, and I want to expose some (not all) of the child class's functions in the parent's interface. To make the example simple, I'll use a Collection as an example:
'MyClass
Private m_ClsMyCollection As Collection
...
'Expose Collection.Count
Public Function Count() As Long
Count = m_ClsMyCollection.Count
End Sub
Simple enough, but I'm hitting a bit of a sticking point when exposing methods with optional parameters. For example, Collection.Add is declared as
Collection.Add(Item, [Key], [Before], [After])
I'm not sure how to wrap this. Is it safe to simply do:
Public Sub Add(Item, Optional Key, Optional Before, Optional After)
m_ClsMyCollection.Add Item, Key, Before, After
End Sub
Presumably if the optional parameters are missing, it will pass Nothing to those parameters in m_ClsMyCollection.Add, but I suspect that passing Nothing is not equivilent to not passing an argument at all.
The alternative seems to be to check IsMissing on each arg and write a pass for every possible combination of arguments, which seems mad:
Public Sub Add(Item, Optional Key, Optional Before, Optional After)
If IsMissing(Key) And IsMissing(Before) And IsMissing(After) Then
m_ClsMyCollection.Add Item:=Item
ElseIf IsMissing(Key) And IsMissing(Before) Then
m_ClsMyCollection.Add Item:=Item, After:=After
ElseIf IsMissing(Key) And IsMissing(After) Then
m_ClsMyCollection.Add Item:=Item, Before:=Before
...
End Sub
The amount of combinations increases exponentially with the number of optional args - even with just 3, I need to check 8 cases! Is this necessary? Is there a better way?