Re: "C++ with Interfaces" (article in CUJ vol 22 no 9)

From: Aguilar, James (jfa1_at_cec.NOBOTSwustl.edu)
Date: 08/05/04


Date: Wed, 4 Aug 2004 18:29:45 -0400


"Victor Bazarov" <v.Abazarov@comAcast.net> wrote in message
news:bE9Qc.454$191.314@newsread1.dllstx09.us.to.verio.net...
> [snip]

Interfaces can be useful. Here's an example:

Suppose I have a system in which there are bunches of objects graphically
drawn on the screen (yes, I know that can't be done in STL, it's just an
example). Suppose I want to implement a drag and drop UI. I want some
objects to be able to be able to have other objects dropped on them, but I
want other objects not to have that functionality. Hence, I create an
interface:

class DropTargetable
{
public:
  virtual bool canAcceptDrop(DrawnObj info) = 0;
  virtual void acceptDrop(DrawnObj info) = 0;
}

Methods that dealt with a dropping would simply call canAcceptDrop on
whatever they were trying to drop something on, and if it could, they would
call accept drop, where info would be whatever the user had clicked on.

That example is probably more practical than looking at a FooBar example.

Yours,

James

PS, if I missed the point, sorry. =) This is just what I understood to be
your question about interfaces.