Unit of Work in C# | Design Patterns | C#

, ,

The Unit of Work pattern is designed to maintain a list of business objects that have been changed by a business transaction, whether by adding, removing, or updating. The Unit of Work then coordinates the persistence of the changes and any concurrency problems flagged. The benefit of utilizing the Unit of Work in your DAL is to ensure data integrity; if an issue arises partway through persisting a series of business objects as part of a transaction, all changes should be rolled back to ensure that the data remains in a valid state.

Watch this space for more code level explanation

Chain Of Responsibility - Design Patterns

, ,

Adapter Pattern - Design Patterns

, ,

When To Go for Adapter Pattern

  • A class that would be useful to your application does not implement the interface you require
  • You are designing a class or framework and you want to ensure it is usable by a wide variety of as yet unwritten classes and applicaations

Scenario for Adapter Pattern

Adapter Pattern Implemented

Intent of the Adapter Pattern

  • Convert the interface of a class into another interface clients expect
  • Allow classes to work together that couldn't otherwise due to incompatible interfaces
  • Future-proof client implementations by having them depend on Adapter Interfaces, rather than concrete classes directly

Use the Adapter Pattern when:

  • You want to use an existing class, but its interface does not match the one you require
  • You want to create a reusable class that cooperates with unrelated or unforeseen classes (i.e. classes that won't necessarily share the same interface)
  • You need to use several existing sub-classes, but it's impractical to adapt their interface by sub-classing everyone

Structure of Adapter Pattern

Other Patterns that use Adapter Pattern

  • Repository - Repository pattern is a very common use of the Adapter pattern
  • Strategy - Adapter pattern is often passed into a class that depends on it, thus implementing the strategy pattern
  • Facade - Adapter and Facade are both wrappers. The facade pattern attempts to simplify the interface and often wraps many classes, while the Adapter typically wraps a single Adaptee, and is not generally concerned with simplifying the interface