When to Use Delegates Instead of Interfaces
来源:互联网 发布:购物资讯类 建站 编辑:程序博客网 时间:2024/05/16 13:05
Both delegates and interfaces enable a class designer to separate type declarations and implementation. A given interface can be inherited and implemented by any class or struct. A delegate can be created for a method on any class, as long as the method fits the method signature for the delegate. An interface reference or a delegate can be used by an object that has no knowledge of the class that implements the interface or delegate method. Given these similarities, when should a class designer use a delegate and when should it use an interface?
Use a delegate in the following circumstances:
An eventing design pattern is used.
It is desirable to encapsulate a static method.
The caller has no need to access other properties, methods, or interfaces on the object implementing the method.
Easy composition is desired.
A class may need more than one implementation of the method.
Use an interface in the following circumstances:
There is a group of related methods that may be called.
A class only needs one implementation of the method.
The class using the interface will want to cast that interface to other interface or class types.
The method being implemented is linked to the type or identity of the class: for example, comparison methods.
- When to Use Delegates Instead of Interfaces
- When to Use Delegates Instead of Interfaces (C# Programming Guide)
- 干活来袭:Effective Concurrency: Know When to Use an Active Object Instead of a Mutex
- When to use Tomcat CATALINA_OPTS instead of JAVA_OPTS - See more at: http://www.tikalk.com/java/when
- use sys_guid() to instead of sequence
- When to use comparable and comparator interfaces in java
- When would someone use Apache Tez instead of Apache Spark, or vice versa?
- Speed of direct calls vs interfaces vs delegates vs virtuals
- use supervisor instead of nohup
- DEPRECATED: Use of this script to execute hdfs command is deprecated. Instead use the hdfs command
- How to get a notification from Linux when the set of network interfaces changes
- When to use DMU?
- When to use AtomicReference?
- An effective way to use pattern to instead of multiple if else statements
- How to use SQL store procedure to trace SQL performance instead of SQL profiler
- How to use USB to do charger detection instead of PMIC?
- how to use Decimal by default instead of float in python
- 5 Reasons to Use Protocol Buffers Instead of JSON For Your Next Service
- js小题目测试你是否真的搞懂JavaScript了
- 如何在DBGrid的每一行前加一个单选框
- Nested Loops Join(嵌套连接) ,优化inner join的查询速度
- cocos2d-iphone源码分析(1):场景
- 关于包装类中的"等等"
- When to Use Delegates Instead of Interfaces
- atomikos 创建数据源,报Max number of active transactions reched:50 错误
- FlashBuilder安装SVN插件-Subclipse
- OpenStack源码阅读1之nova-api服务启动
- 使用Maven,即使存在*.lastUpdated文件也能更新jar文件的方法
- 第2章 对象的创建与使用(一)
- transient关键字
- cocos2d-iphone源码分析(2):Director
- hcitool 使用与分析