简体   繁体   English

引用其实现的内部类的接口

[英]Interface referencing an inner class of its implementation

I am refactoring a piece of code and I have to made a method (lets call it myMethod ) in one class (let's call it TestImpl ) from private to public . 我正在重构一段代码,并且必须在一个从privatepublic类(称为TestImpl )中创建一个方法(称为myMethod )。 Therefore, I try to add this method to its interface ( ITest ). 因此,我尝试将此方法添加到其接口( ITest )。

However, the problem is that a parameter of the method references to an inner class of TestImpl . 但是,问题在于该方法的参数引用了TestImpl的内部类。 ie something like: 即类似:

myMethod (TestImpl.NewType var1, ...)

This seems a bit weird to me as the interface references to its own implementation. 对于我来说,这有点奇怪,因为该接口引用了它自己的实现。 What is the best solution here? 最好的解决方案是什么? Or, is it really a problem? 还是真的有问题吗?

As I understand it's static class, then it shouldn't be a problem. 据我了解,它是静态类,那么这应该不是问题。 However, I think it's better to move that NewType out of TestImpl or even create new interface to generalize this NewType 但是,我认为最好将NewTypeTestImpl ,甚至创建新接口以概括此NewType

It violates the DI principles, Interface should not have nay compile dependencies to its implementations. 它违反了DI原则,Interface不应该对其实现进行编译依赖。 NewType should be extracted as a interface or class to outside. NewType应该作为外部的接口或类提取。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM