File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes Class form Adapter VS Object form Adapter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Class form Adapter VS Object form Adapter" Watch "Class form Adapter VS Object form Adapter" New topic
Author

Class form Adapter VS Object form Adapter

Qunfeng Wang
Ranch Hand

Joined: Jan 28, 2005
Posts: 433
The "Class form" and "Object form" often appears in GOF book. What does that mean by "Class form" and "Object form"?

As for the Adapter pattern, the class form is implementing two interfaces; the object form is using composite to delegate.


To be or not to be. It's a question.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
I think you already got it: the class form uses inheritance, whereas the object form uses composition. There isn't more to it, as far as I can tell...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by Louis Wang:
As for the Adapter pattern, the class form is implementing two interfaces; the object form is using composite to delegate.


Some languages (especially when GOF was first published) supported only single inheritance. Without multiple inheritance or interfaces you cannot implement the class form but as long as you have single inheritance you can still implement the object form.

You can sometimes see a variation of the "object form" in Java when a class doesn't implement an interface itself but lets one of it's (anonymous) inner classes do it.

Robert C. Martin's article on the Interface Segregation Principle (pdf) talks about the differences between the object form (separation through delegation) and class form (separation through multiple inheritance) of the Adapter.
[ April 19, 2007: Message edited by: Peer Reynders ]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
There is another big advantage to the object form: you can use the object form to adapt an object that has already been created. With the class form, you need to be able to control the instanciation of the original object, so that the adapter instance is created.

I regularly use the object form for that reason.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class form Adapter VS Object form Adapter