简体   繁体   中英

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 . Therefore, I try to add this method to its interface ( ITest ).

However, the problem is that a parameter of the method references to an inner class of 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

It violates the DI principles, Interface should not have nay compile dependencies to its implementations. NewType should be extracted as a interface or class to outside.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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