G
Guest
I know this sounds contrary to the idea of an interface, but read this and
see what you think
-----------------------------------------------------------------------------------------
It would be nice if there was a way for a class to create a special type of
interface, a private one. Private meaning it's not directly exposed at the
class level, you need to be explicitly handed a reference to it by the class.
Often the encapsulation issue is you need to implement an interface (as a
callback or some other functionality is required), but doing so exposes all
of those interface methods to any user of your class, breaking encapsulation.
So the only alternative is to then have an internal proxy class implement the
interface and proxy all of the calls to that. This would be much easier of a
class can implement a private interface that could selectively be handed out.
This way the integrity of the encapsulation is protected without requiring
the user to write a proxy class.
An example might be something like (I'm sure there could be better syntax):
public interface IMyInterface
{
void Callback();
}
class MyInterfaceUser
{
public void SetUseInterface(IMyInterface usethis)
{
// ...
{
}
class MyClass : private IMyInterface
{
MyClass(MyInterfaceUser user)
{
user.SetUseInterface(this.PrivateInterface(IMyInterface));
}
protected void Callback()
{
//...
}
}
see what you think
-----------------------------------------------------------------------------------------
It would be nice if there was a way for a class to create a special type of
interface, a private one. Private meaning it's not directly exposed at the
class level, you need to be explicitly handed a reference to it by the class.
Often the encapsulation issue is you need to implement an interface (as a
callback or some other functionality is required), but doing so exposes all
of those interface methods to any user of your class, breaking encapsulation.
So the only alternative is to then have an internal proxy class implement the
interface and proxy all of the calls to that. This would be much easier of a
class can implement a private interface that could selectively be handed out.
This way the integrity of the encapsulation is protected without requiring
the user to write a proxy class.
An example might be something like (I'm sure there could be better syntax):
public interface IMyInterface
{
void Callback();
}
class MyInterfaceUser
{
public void SetUseInterface(IMyInterface usethis)
{
// ...
{
}
class MyClass : private IMyInterface
{
MyClass(MyInterfaceUser user)
{
user.SetUseInterface(this.PrivateInterface(IMyInterface));
}
protected void Callback()
{
//...
}
}