2

Possible Duplicate:
How do you declare an interface in C++?

Hi,

What's the preferable way to create single interface and multiple implementations in c++?

For example, I'd like to implement kqueue for mac and epoll for linux and share the interface.

Thank you

Community
  • 1
  • 1
eugene
  • 39,839
  • 68
  • 255
  • 489
  • I would in this case try to keep the interface in the header general enough so it works with either implementation, and just make two different detail source files and `#ifdef #include` the right one from a third one. This is not as elegant, but it works. The reason why I would go this way is that it is kind of pointless to use a sophisticated pattern that can decide at runtime if it is clear from the beginning that you will only ever use one implementation on a particular platform. – Damon May 03 '11 at 08:49

1 Answers1

2

The Strategy Pattern is probably what you are looking for.
The Abstract Factory Pattern can help you fill in the right implementation when starting up.

stefaanv
  • 14,072
  • 2
  • 31
  • 53