"Callbacks" (usually events in C#) have always been problematic for multithreaded programming. This is because a good rule of thumb for component design is: Do your best to allow the event handler to do anything. Since "communicate with another thread that is attempting to take any lock" is one example of "anything", a natural corollary of this rule is: Never hold locks during callbacks.
Cytat:
A general-purpose solution does not exist, and all other solutions have serious drawbacks (placing severe restrictions on the actions available to the event handler).
One benefit of using the dependency injection approach is the reduction of boilerplate code in the application objects since all work to initialize or set up dependencies is handled by a provider component.
Another benefit is that it offers configuration flexibility because alternative implementations of a given service can be used without recompiling code. This is useful in unit testing, as it is easy to inject a fake implementation of a service into the object being tested by changing the configuration file, or overriding component registrations at run-time.
Furthermore, dependency injection facilitates the writing of testable code.
W sumie taka sobie 3/5. Przegadana. Wystarczy przekartkować.
1. Introduction
What Is a Design Pattern? * Design Patterns in Smalltalk MVC * Describing Design Patterns * The Catalog of Design Patterns * Organizing the Catalog * How Design Patterns Solve Design Problems * How to Select a Design Pattern * How to Use a Design Pattern
2. A Case Study: Designing a Document Editor
Design Problems * Document Structure * Formatting * Embellishing the User Interface * Supporting Multiple Look-and-Feel Standards * Supporting Multiple Window Systems * User Operations * Spelling Che cking and Hyphenation * Summary