Don Box highlights some of the similarities and differences between using delegates or interfaces to integrate two pieces of code. This is always a decision I have struggled with in the past, and Don's example provides some interesting insight:
Both approaches require an explicit step to integrate the two pieces of code. The fundamental difference between the two approaches is that the delegate-based design requires that explicit step to take place at the point of integration, not at a particular type definition. The delegate-based approach specifically does not assume that the target method will have any awareness of its integration partner, rather, it's just a method that can be called by anyone with sufficient security/access permissions. In contrast, the interface-based approach requires the target method to have an a priori understanding of the integration contract (IPredicate in this example).
Don's point is ultimately that delegates provide easier reuse of existing code, and thus help to create more loose coupling between components and libraries.
All content is
Copyright (c) 2008 Jorgen Thelin. All rights reserved.
The opinions expressed here represent my own views
and not necessarily those of my current, prior or future employer(s).
Content is provided "as-is", without any representations or warrenties of any kind.
Contents of the Weblog Feed are
licensed under a
Creative Commons License.