-2

Is it possible to implement class adapter pattern in Java?

I'm trying to read everything on the internet but still have found an example.

Danubian Sailor
  • 1
  • 38
  • 145
  • 223
user2342185
  • 11
  • 1
  • 6

2 Answers2

2

It is possible, but pure interfaces must be used instead of abstract classes, since Java does not support multiple inheritance.

arshajii
  • 127,459
  • 24
  • 238
  • 287
1

There are two variations of the Adapter pattern: inheritance-based (a.k.a. class Adapter) and composition-based. The inheritance variation requires the use of multiple inheritance, which doesn't exist in Java and therefore it's impossible to implement. But of course, you can do the composition-based implementation, without any problems.

Óscar López
  • 232,561
  • 37
  • 312
  • 386
  • There are two types of adapters. Java code implements the Object Adapter pattern in a bunch of places, but the Class Adapter requires multiple inheritance (or at least something resembling it). – cHao Jun 25 '13 at 01:42
  • I'm aware. I updated my answer to reflect this. – Óscar López Jun 25 '13 at 01:44