Share via


Design Patterns

In software architecture and development, a pattern is a description of a recurring problem that occurs in a specific context and, based on a set of guiding forces, suggests a solution. The solution is usually a simple mechanism because it is a collaboration between two or more classes, objects, services, processes, threads, components, or nodes that work together to solve the underlying architecture or development challenge.

Patterns are useful to developers and architects because they do the following:

  • They document simple mechanisms that work.
  • They provide a common vocabulary and taxonomy for developers and architects.
  • They allow solutions to be described concisely as combinations of patterns.
  • They enable reuse of architecture, design, and implementation decisions.

The Enterprise Library application blocks use the following patterns (among others):

  • Plug-in pattern. This pattern extends the behavior of a class by allowing extensions to plug into an abstract class that, in turn, plugs into a core class. This creates a new subclass that includes only the capabilities required in the specific context.
  • Dependency Injection pattern. With this pattern, you can inject objects into a class, instead of relying on the class to create the object.

For more information about patterns, see the Microsoft patterns & practices Web site.

Plug-in Pattern

The Plug-in pattern is a software pattern that creates an object instance of an interface at run time. The Plug-in pattern extends the behavior of an existing class so that it can be used for a more specific purpose. It differs from using class inheritance, where behavior is altered or overwritten, or configuration, where behavior modification is limited to the capabilities of the defined configuration options.

With the Plug-in pattern, the modified behavior (the plug-in) connects to an abstract partial class, which, in turn, connects to the core class. The plug-in uses this interface to implement methods called by the core class and can also call new methods at the core class.

Dependency Injection Pattern

The Dependency Injection pattern allows you to inject objects into a class, instead of relying on the class to create the object. This is particularly helpful in situations where you want to decouple the details of a particular implementation or deployment from your application code. The Dependency Injection pattern decouples services or other code that an application might be dependent on from the application itself and packages it in a container. Then, the responsibility for handling the code interdependencies—including object creation and linking—are removed from the objects themselves and transferred to another entity. Unlike with the Factory pattern, with the Dependency Injection pattern, code in containers can be shared by multiple applications.

The System.ComponentModel namespace is a Microsoft® implementation of the Dependency Injection pattern. In the Enterprise Library, Unity implements the Dependency Injection pattern.

For more information about the Dependency Injection pattern, see Inversion of Control Containers and the Dependency Injection Pattern. For more information about the dependency injection container model in Enterprise Library, see The Dependency Injection Model.