Re: "All public methods should be virtual" - yes or no / pros & cons

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Martin Maat [EBL] (dummy_at_somewhere.nl)
Date: 01/31/04


Date: Sat, 31 Jan 2004 23:01:24 +0100


"Bret Pehrson" <bret@infowest.com> wrote in message
news:401C0D32.33A421ED@infowest.com...
> > The behavior of the class is changed by sub-classing it. What is the
point
> > of stating that a base class is not changed by the descendant? The way
we
> > look at it there is no point in creating a descendent class if not
either
> > behavior or data members are changed./ extended.

> I agree that overriding to change behavior is half of the story. The
other
> half overriding to create/monitor/track an object's methods. I tried
giving an
> example of such a case before, just to point out that you can't limit
'virtual'
> discussions just to the modification of behavior since it is perfectly
> legitimate to override a method and *not* change any behavior.

Okay, I understand your point now. You are saying it is not a crime to use
polymorphism as an event mechanism. For debugging purposes as in your
example I do not see any harm either. As a design pattern though I say it
should not be done if a more dedicated events mechanism is available in the
particular development environment.

That summarizes most of the noise we all generated on the subject. :-)

Martin.



Relevant Pages

  • Re: Language enhancements
    ... A base class that provides a virtual method must account for that in its ... If you find it necessary, in creating a descendant, to nullify ... code implemented by the ancestor, then that code should not be in the ... Same applies to contracts; descendants should not break ancestor contracts, ...
    (borland.public.delphi.non-technical)
  • Re: How to create an instance of a class by class name in a string?
    ... > I have an application that has one base class and several descendant ... classes (13 ÷classes and the class name in a String. ... var descendantclass:tcbase; ...
    (comp.lang.pascal.delphi.misc)
  • Re: Language enhancements
    ... Everything that is true for a base class should be true ... > Hmm. ... A descendant methods can easily return dfferent results for the ... "plugin site"), but in this case again, any tests at the ancestor level ...
    (borland.public.delphi.non-technical)
  • Re: Global variable or reading from IniFile?
    ... >which gets implemented with some minor modifications for each project. ... Each application uses a descendant of the base class, addiing ...
    (borland.public.delphi.language.objectpascal)