Interface is a protocol for implementors and users. So it can be used to implement callback function which is wildly used in many other areas. The interface is much more powerful than class or abstract class. Interfaces can be inherited and extended. A class can inherit multiple interfaces.
Inner class gives us convenience to have more than one implementation of an interface in a class. This is pretty useful in some cases when you need to have multiple implementation of some interface or callback. Event handlers in GUI, for instance, take a lot advantage of anonymous class. That is also the place in which we use inner class most.
Although they provide use more options and more powerful solutions, interfaces and inner class should be considered in design phase. Inappropriate usage of them could cause serious problems in implementation phase and maintenance phase. We should learn when and where to use, rather than how to use them. Also, we should learn to use them to improve our solutions not causing new problems.
本文探讨了接口和内部类在软件设计中的作用与优势。接口作为一种强大的协议工具,不仅支持回调函数实现,还能被继承和扩展。一个类可以继承多个接口。内部类则为同一类中实现多个接口提供了便利,尤其是在GUI事件处理等场景下,匿名内部类的应用非常广泛。然而,不当使用这些特性可能会导致实施和维护阶段的问题。
898

被折叠的 条评论
为什么被折叠?



