码迷,mamicode.com
首页 > 其他好文 > 详细

控制反转 (inversion of control)

时间:2015-09-07 12:57:13      阅读:185      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!