I was under the impression interfaces had to be implemented with public methods in order to be callable from outside. Just found this isn’t true and want to use it in my design but it’s still so novel and doesn’t feel quite right.
So basically even if a method is marked Private or Protected it’s still always accessible through the interface type. Haven’t found anything specifically mentioning this (is there) and want to make sure I can rely on it.
[code]Interface Interface1
Sub Foo()
End Interface
Class Class1 Implements Interface1
Private Sub Foo()
// Part of the Interface1 interface.
End Sub
End Class
Sub Action()
dim c As new Class1 //c.Foo //can’t call, Foo is private
dim i As Interface1 = c
i.Foo //accessible
End Sub[/code]
Also, while researching this I discovered the ‘Implements’ feature of methods that allows renaming the interface method names (very nice!).
Its been there for such a long time but I doubt anyone uses it widely this way.
Joe’s out today.
His opinion, or Mars, on bug vs feature would be good as its been present for a VERY long time.
[quote=139413:@Norman Palardy]Its been there for such a long time but I doubt anyone uses it widely this way.
Joe’s out today.
His opinion, or Mars, on bug vs feature would be good as its been present for a VERY long time.[/quote]
IMO Feature… at least I use it that way when I ONLY want certain methods exposed in certain situations. After all YOU determine if the interface exposes an otherwise inaccessible method so intension is explicit.
IIRC Aaron had a blog post about how this feature can help define fiend classes by defining teh interface in a module and restricting the interface scope to the module
That was private interfaces in a module and I’ve used that
This is slightly different since the class that implements things this way still adheres to the interface but the methods are only accessible through the interface
I could certainly believe that’s by design - I know its been discussed at least one life time ago - I just can’t find it
AND I just peeked in the Ramblings on REALbasic pdf and there it is (page 217/218)
Seems it was by design - as that way you can ONLY use the interface which isn’t a bad thing.