-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
  • 22,047
  • 37
  • 140
  • 217
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
  • 123,543
  • 24
  • 232
  • 276
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
  • 225,348
  • 35
  • 301
  • 374
  • 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