The Client Interface describes a protocol that other classes must follow to be able to collaborate with the client code. The Client is a class that contains the existing business logic of the program. When an adapter receives a call, it translates the incoming XML data into a JSON structure and passes the call to the appropriate methods of a wrapped analytics object. Then you adjust your code to communicate with the library only via these adapters. To solve the dilemma of incompatible formats, you can create XML-to-JSON adapters for every class of the analytics library that your code works with directly. Sometimes it’s even possible to create a two-way adapter that can convert the calls in both directions. Upon receiving a call, the adapter passes the request to the second object, but in a format and order that the second object expects.Using this interface, the existing object can safely call the adapter’s methods.The adapter gets an interface, compatible with one of the existing objects.For example, you can wrap an object that operates in meters and kilometers with an adapter that converts all of the data to imperial units such as feet and miles.Īdapters can not only convert data into various formats but can also help objects with different interfaces collaborate. The wrapped object isn’t even aware of the adapter. This is a special object that converts the interface of one object so that another object can understand it.Īn adapter wraps one of the objects to hide the complexity of conversion happening behind the scenes.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |