Patch for kabc resources

Christian Loose christian.loose at hamburg.de
Tue Jan 6 19:58:43 GMT 2004


Am Dienstag, 6. Januar 2004 18:53 schrieb David Faure:
> On Tuesday 06 January 2004 18:45, Tobias Koenig wrote:
> > On Tue, Jan 06, 2004 at 05:15:38PM +0100, Holger Freyther wrote:
> > > On Tuesday 06 January 2004 17:04, Tobias Koenig wrote:
> >
> > Hi,
> >
> > > > On Tue, Jan 06, 2004 at 02:57:39PM +0100, Bo Thorsen wrote:
> > > > Hi Bo,
> > > > I'd like to keep this method to have an additional abstraction layer
> > > > to add new config items. Cornelius?
> > >
> > > In what way to add? This is a virtual function right? So we want to
> > > force Resources to call the base class method so we can add config
> > > items there later? This sounds broken. In the case where we want/must
> > > to be called we should use other techniques.
> >
> > The writeConfig() method of the base class has to be called, because
> > KRES::Resource writes some standard config items to the file.
> >
> > Is there any nice design pattern wich covers this issue, so that the
> > method of the base class don't have to be called from every
> > implementation explicitely?
>
> An easy solution is to separate the public method from the virtual,
> protected, method. Hmm, well the public method is also virtual here, so
> this would give something like
>
> public:
>  // DO NOT REIMPLEMENT IN SUBCLASSES
>  virtual void writeConfig() {
>     doWriteConfig();
>     BaseClass::writeConfig();
>  }
>
> protected:
>   virtual void doWriteConfig() { }
>
> This way you know for sure that the baseclass method is always called,
> and subclasses should only reimplement doWriteConfig (better name
> needed, like writeResourceConfig() or anything more appropriate).

You could also make the doWriteConfig() private. See 
http://www.gotw.ca/publications/mill18.htm





More information about the kde-core-devel mailing list