首页 > 其他 > 详细

控制反转 (inversion of control)

时间:2015-09-07 12:54:06      阅读:246      评论:0      收藏:0      [点我收藏+]

The inversion of control (IoC) pattern is abstract; it says that one should move dependency creation
out of the consumer class, but it doesn’t talk about exactly how to achieve that.

 

 

public class EmailService
{
public void SendMessage() { ... }
}

 


public
interface IMessagingService { void SendMessage(); } public class EmailService : IMessagingService { public void SendMessage() { ... } } public class NotificationSystem { private IMessagingService svc; public NotificationSystem() { svc = new EmailService(); } public void InterestingEventHappened() { svc.SendMessage(); } }

 

控制反转 (inversion of control)

原文:http://www.cnblogs.com/yangyangss/p/4788466.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!