Home > Articles > Programming > C#

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Summary

The ADAPTER pattern lets you use an existing class to meet a client class's needs. When a client specifies its requirements in an interface, you can usually create a new class that implements the interface and subclasses an existing class. This approach creates a class adapter that translates a client's calls into calls to the existing class's methods.

When a client does not specify the interface it requires, you may still be able to apply ADAPTER, creating a new subclass class of the client that uses an instance of the existing class. This approach creates an object adapter that forwards a client's calls to an instance of the existing class. This approach can be dangerous, especially if you don't (or perhaps can't) override all the methods that the client might call.

Data flow in the .NET architecture provides many examples of adaptation, but few examples of the ADAPTER pattern. This is arguably a missed opportunity that occurs when a class such as DataGrid does not define its needs in an interface. When you architect your own systems, consider the power and flexibility that you and other developers can derive from an architecture that uses ADAPTER to advantage.

  • + Share This
  • 🔖 Save To Your Account