假设如果我试图通过像这样的其他类访问一个类的方法
class SuperClass
{
public interface ISubject
{
void Print();
}
private class Subject : ISubject
{
public void Print()
{
Console.WriteLine("this is a print");
}
}
public class Proxy {
ISubject subject;
public void CallOtherMethod() {
subject = new Subject();
subject.Print();
}
}
}
class Client: SuperClass
{
static void Main() {
Proxy proxy = new Proxy();
proxy.CallOtherMethod();
}
}
这被称为代理类吗?或者它是否需要有一个接口作为参考然后我们必须调用该方法?例如像这样
class SuperClass
{
public interface ISubject
{
void Print();
}
private class Subject : ISubject
{
public void Print()
{
Console.WriteLine("this is a print");
}
}
public class Proxy : ISubject
{
ISubject subject;
public void Print()
{
subject = new Subject();
subject.Print();
}
}
}
class Client : SuperClass
{
static void Main()
{
ISubject proxy = new Proxy();
proxy.Print();
}
}