向接口添加Extra方法 [英] Adding Extra method to interface

查看:70
本文介绍了向接口添加Extra方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对界面有一个棘手的问题。请尝试给我一个解决方案。

I have a tricky question on interface. Please try to give me a solution for it.

场景:
我用五种方法编写了一个接口。此外,我已使用此接口实现了100多个类。现在,我需要在界面中再添加一个方法。因此,我需要在所有类中定义相同的方法。我怎么能避免这个?

Scenario: I have written an interface with five methods. Also I have implemented more than 100 classes using this interface. Now, I need to add one more method to the interface. Consequently, I will need to define the same method in all classes. How can I avoid this???

请回复...

谢谢,
Akif

Thanks, Akif

推荐答案

您是否可以避免通过创建从第一个接口继承然后仅更改的新接口来向接口添加方法你需要那些新方法的类?因此,如果 foo 不需要新方法,请不要管它,但如果 bar ,则将其更改为新界面。

Could you avoid adding a method to the interface by instead creating a new interface which inherits from that first interface and then only changing the classes you need that new method on? Hence, if foo didn't need the new method, leave it alone but if bar did, change it to the new interface.

这篇关于向接口添加Extra方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆