【发布时间】:2021-12-18 12:46:03
【问题描述】:
假设我有如下代码
interface Interface1
{
void method1();
}
interface Interface2
{
void method2();
}
class ClassWithInterfaces : Interface1,Interface2
{
void method1(){}
void method2(){}
}
现在在我的“经理”类中,我按如下方式实现:
public OtherClass
{
Interface1 interface1;
Interface2 interface2;
public void someMethod()
{
ClassWithInterfaces classWithInterfaces = new ClassWithInterfaces();
interface1 = classWithInterfaces;
interface2 = classWithInterfaces
}
}
我不认为这是正确的方法,但是如果您问这个问题,我无法提出其他解决方案,我无法在我的项目中使用依赖注入框架。你能告诉我除了 DI 之外是否还有更好的方法?
【问题讨论】: