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)
关键词: