为什么我们要实现接口? [英] Why we are implementing interfaces ?

查看:130
本文介绍了为什么我们要实现接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么要实施,比如ICloneable或IDisposable的。我不要求什么ICloneable或IDisposable的事,但我想学什么来实现这些接口很好的理由,而不是仅仅写这处置或方法克隆我们的对象?

Why are we implementing, for example ICloneable or IDisposable. I'm not asking what ICloneable or IDisposable do, but I want to learn what's a good reason to implement these interfaces rather than just writing a method which disposes or clones our objects?

推荐答案

使用接口​​保持使用功能一致的那件。这样,当另一个类要/需要使用你的类,它可以在它作为一个可复制的,一次性的对象,而不必担心您的具体实施细则。

Using interfaces keeps the use of those pieces of functionality consistent. That way, when another class wants to / needs to use your class, it can act on it as a cloneable, disposable object without worrying about your particular implementation details.

这篇关于为什么我们要实现接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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