About interface and inner class

来源:互联网 发布:杀破狼 js主唱去世 编辑:程序博客网 时间:2024/06/05 13:21

Interface is a protocol for implementors and users. So itcan be used to implement callback function which is wildly used in many otherareas. The interface is much more powerful than class or abstract class. Interfacescan be inherited and extended. A class can inherit multiple interfaces.

Inner class gives us convenience to have more than oneimplementation of an interface in a class. This is pretty useful in some caseswhen you need to have multiple implementation of some interface or callback.Event handlers in GUI, for instance, take a lot advantage of anonymous class. Thatis also the place in which we use inner class most.

Although they provide use more options and more powerfulsolutions, interfaces and inner class should be considered in design phase. Inappropriateusage of them could cause serious problems in implementation phase andmaintenance phase. We should learn when and where to use, rather than how touse them. Also, we should learn to use them to improve our solutions notcausing new problems.

 

原创粉丝点击