adapter design pattern
DESCRIPTION
Adapter Design Pattern ExplainedTRANSCRIPT
Adapter Pattern
Shahriar Iqbal Chowdhury & Monjurul Habib Code Name: Remington
http://www.facebook.com/groups/netter/
What is Adapter• A device for connecting pieces of equipment that cannot be connected directly
• An adapter allows classes to work together that normally could not because of incompatible interfaces
Missing something??
How does it work?
When we need?
• Convert the interface of a class into another interface that client expects.• Allow classes to work together that couldn’t because of incompatible interfaces.• Future clients can be satisfied through the creation of additional concrete Adapter.• Adapter is meant to change the interface of an existing object. • A way to achieve OCP(Open/Closed Principle)
Client Component
Compo
nent/
Adap
tee
AdapterClient
Adapters in the real world
UML Structure
Way to use (ref. DoFactory)
Client
Adapter
Adaptee
Another shocking example
Adapter @.NET Framework• From .NET-based code you can easily call legacy COM objects and vice versa.
• Behind the scenes, Visual Studio® .NET create a Runtime Callable Wrapper (RCW) class. Inside the RCW, .NET specific format is converted into a format that the COM component expects and vise versa.
• Data Adapters adapts data from different source (SQL Server, Oracle, ODBC, OLE DB) to dataset.
• Different Data Adapter classes are usedSqlDataAdapterOdbcDataAdapterOleDbDataAdapter
Real World Scenario’s
• Most of the applications using third party libraries use adapters as a middle layer between the application and the 3rd party library.• Memory card reader software