[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: KParts API: thinking about the future (patch)
From:       aleXXX <alexander.neundorf () gmx ! net>
Date:       2002-03-03 23:15:32
[Download RAW message or body]

On Sunday 03 March 2002 22:17, Martijn Klingens wrote:
> On Sunday 03 March 2002 21:49, David Faure wrote:
> > [ ... ]
>
> I don't think I have to explicitly express my approval here, that should be
> clear :-)
>
> I do have some thoughts about it, though that I came up with just after
> David moved our private discussion to kde-core-devel.
>
> Would it be a good idea to use the Template Method pattern instead that
> Dawit mentioned on kde-cvs last week? That might be even more flexible.
> What the API would be like then is
>
> public:
>   bool openStream() { return doOpenStream(); }
>   bool writeStream( const QDataStream &s ) { return doWriteStream( s ); }
>   bool closeStream() { return doCloseStream(); }
> private:
>   virtual bool doOpenStream() { return false; }
>   virtual bool doWriteStream( const QDataStream& ) { return false; }
>   virtual bool doCloseStream() { return false; }

Isn't it quite pointless to make a private function virtual ?

> With the function bodies of the public API specified in the cpp file and
> not in the .h, so we can add code around it when needed in the future.

Whether the implementation is in the header or in the cpp doesn't really 
matter, except for inlining. We can do it also with David's approach. Simply 
implement your own version of the public virtual functions. You could even do:

class MyPartThingy:public KParts::ReadOnlyPart {
...
public:
   virtual bool openStream() {return doOpenStream();}
   virtual bool writeStream(const QDataStream &s) {return doWriteStream(s); }
   virtual bool closeStream() { return doCloseStream(); }
private:
   virtual bool doOpenStream() { return false; }
   virtual bool doWriteStream( const QDataStream& ) { return false; }
   virtual bool doCloseStream() { return false; }
...
};

> Can't think of a use yet, but for public API it might be worthwhile to
> think broad...

Where's the difference between

public:
   virtual bool doSomething();

and 
public:
   bool doSomething();    //calls doSomethingImpl();
protected:
   virtual bool doSomethingImpl();


I don't see any.

Bye
Alex
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic