I have a derived class which has no variables but simply adapts the interface to another class - is there a special name for such a class in C++?
+7
A:
It "adapts" the interface? Assuming that means that it exposes the same behaviour, but with different method calls (or perhaps, slight behavioural changes), then we tend to call that an Adapter. It's a common design pattern.
Related is the Facade pattern, which is an Adapter that simplifies an API. For example, it may provide sensible parameter defaults, or abstract some of the necessary call flow into a unit that can be called by other code.
Rob
2009-09-04 22:14:06
Couldn't have said it better myself. :)
ph0enix
2009-09-04 22:18:00
It quite possibly is an adapter, it could still be an adapter even if it had member variables. I don't think either adapter or facade captures both characteristics that the question asks for. But I can't think of a term that does, so I can't really complain.
Steve Jessop
2009-09-05 11:21:04
+1
A:
Rob is correct, what you describe matches the Adapter design pattern.
If it "adapts" more than one class or package behind the scenes, this is also called a Facade.
Shaggy Frog
2009-09-04 22:16:01
Snarfblam: it looks like Rob added his paragraph about Facade after my post.
Shaggy Frog
2009-09-05 00:26:00
That's right; or rather, as I was editing to add the paragraph about Facade, your post came up. I submitted the edit anyway, no harm done.
Rob
2009-09-05 13:24:04