5

Can you explain me about this Extension Object Pattern and how it differ from the Adapter Pattern?

There seems to be only few resources in web that explains the Extension Object Pattern and most of them are bit confusing (at least for me).

Thanks in advance.

Supun Wijerathne
  • 11,964
  • 10
  • 61
  • 87
vishnurajts
  • 307
  • 1
  • 4
  • 12
  • 2
    The difference seems to be that an Adapter hides the wrapped object, while an extendable object is known to the user and is queried explicitly whether it has an extension object for some feature. – Bergi Sep 05 '16 at 13:54

2 Answers2

5

The main difference is in the time of usage:

You would use an Adapter during development of your software, in cases you cannot change the existing interface you introduce an Adapter.

The extension object pattern provides for such changes and enables you to e.g. extend already deployed software.

Also, from the Text you posted:

Adapter supports to adapt an existing interface. The Extension Objects pattern supports additional interfaces. Extension Objects and Adapter can work together in situations where an object needs to be adapted to an extension interface.

PsiX
  • 1,661
  • 1
  • 17
  • 35
3

I think you can get a better idea from this diagram explaining Extension Objects Pattern.

enter image description here

You can see that a client can

  • Add an extension
  • Get(use) an existing extension.

When you compare the Adapter, the client rather stick to an existing adapter.

You can see the different extensions listed on the diagram as different adapters.

Supun Wijerathne
  • 11,964
  • 10
  • 61
  • 87
  • So Adapter pattern - client stick to the existing adapter. But in Extension Object Pattern - Client queries an adapter from available extensions. I hope i understood your point correctly. – vishnurajts Nov 24 '16 at 06:54
  • 1
    @CommonMan yes. and also can add/remove extensions. :)) – Supun Wijerathne Nov 24 '16 at 09:26
  • 1
    @SupunWijerathne you can also implement adapter in such way, that you can add/remove underlying adapters (was one of the requirements at my software engineering course recently). – Coderino Javarino Mar 07 '18 at 19:36
  • @CoderinoJavarino hmm. I'm interested to see your design. Anyway at an absolute glance there is no any single/rigid implementation for any pattern. All the time what we are using is rather an implementation, not the implementation. :)) – Supun Wijerathne Mar 08 '18 at 02:06