1 / 13

API Migration Patterns

API Migration Patterns. November 6 th , 2012 Erik Fredericks. Adapter Pattern. Object Adapter Adapter contains instance of class it wraps. http:// en.wikipedia.org /wiki/ File:ObjectAdapter.png. Adapter Pattern. Class Adapter Implements/inherits both expected and pre-existing interface.

Download Presentation

API Migration Patterns

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. API Migration Patterns November 6th, 2012 Erik Fredericks

  2. Adapter Pattern • Object Adapter • Adapter contains instance of class it wraps http://en.wikipedia.org/wiki/File:ObjectAdapter.png

  3. Adapter Pattern • Class Adapter • Implements/inherits both expected and pre-existing interface http://en.wikipedia.org/wiki/File:ClassAdapter.png

  4. Adapter Sub-types [1] • Layered adapter • Stateful adapter • Delayed instantiation • Wrapping identify map • Terminology

  5. Adapter Sub-types [1] • Layered adapter • Stateful adapter • Delayed instantiation • Wrapping identify map • Terminology Use classic Adapter pattern

  6. Adapter Sub-types [1] • Layered adapter • Stateful adapter • Delayed instantiation • Wrapping identify map • Terminology Completely re-implement by surrogate Surrogate may require multiple combinations of adapteesat runtime

  7. Adapter Sub-types [1] Possible with Adapter sub-types • Layered adapter • Stateful adapter • Delayed instantiation • Wrapping identify map • Terminology Completely re-implement by surrogate Surrogate may require multiple combinations of adapteesat runtime

  8. Layered Adapter • Instead of directly referencing target API types… • Maintain an object of interface type • Alternative mappings uniformly accessed through surrogate • Example • SimpleJListAdapter composes JList and ListModel • ScrollableJListAdapter also inherits from JScrollpane

  9. Stateful Adapter • Delegation not possible • Mapped types don’t agree on features/data • Source API offers richer features than target API • Examples: • Surrogate re-implements missing functionality (a disposed flag) • Adjusting interaction protocols • Client 1 uses a Serializer • Client 2 uses a different protocol • Surrogate collects state and adjusts protocol when dispatching operations

  10. Delayed Instantiation • Surrogate’s lifecycle typically bound to adaptee • API enforces relationships at construction time • Surrogates may need to delay adaptee construction • Example: • JButton <-> Button • JButton can’t create Button until JButton is added to a Container • Parent-child relationship unestablished • Factory design pattern decouples surrogate/adaptee life cycles • Check if instance has been created • Store data temporarily until creation

  11. Wrapping Identity Map • Source APIs may return new object with each call • May be necessary to maintain communication between adapter/adaptee • Query an Identity map for correspondence • Example: • Call to getComponents() : return array of sub-widgets • Identity map queried to get Component surrogate mapped to widget adaptee • If adaptee has no surrogate, one can be created on the fly • Allows for reflective instantiation or hard-coded type mapping

  12. Wrapping Identity Map • Only necessary if surrogate is an object adapter • Class adapters already typed by both APIs and don’t require any translation • Possible issues with memory leaks • Garbage collection procedures must ignore reference in identity map

  13. References • [1] T.T. Bartolomei, K. Czarnecki, and R. Landmmel. Swing to swt and back: Patterns for api migration by wrapping. In Software Maintenance (ICSM), 2010 IEEE International Conference on, pages 1 –10, sept. 2010.

More Related