Adding abstract class...

From: bobsled (sleding_at_sands.com)
Date: 04/24/04


Date: Sat, 24 Apr 2004 17:47:12 GMT

Here's a post from Uncle Bob...

"In C++ dependencies are very expensive, so isolation is that much more
important. Therefore I think it is often best to keep the interface
and add the abstract class below it. In Java or C# the dependencies
are not quite as expensive, and need for isolation not quite as great.
However, since abstract classes cannot be multiply inherited, it's
still probably best to keep the interface and add the abstract class
below it.

On the other hand, if you started with an abstract class, and did not
have an interface; and if the system was working well without the
interface, I'm not sure I'd add it right away. I'd wait until some
event occurred that made the need for the interface obvious."

I have some question and want to ask him:

1. Is the difference between interface and abstract base class is the former
consists only pure virtual functions but no member of data and no
non-pure-virtual function, and the latter has at least one pure virtual
function and either some members of data or non-pure-virtual function?

2. Is keeping adding such kind of abstraction into class hierarchy not going
to gain performance penalty?

3. Is there any general rule for such kind of adding abstract class?

Thank you for your comments!



Relevant Pages

  • Re: Declaring a Constructor in an Interface?
    ... i have read many places that an interface is faster than ... but would You also claim that an abstract class ... Dennis JD Myrén ... > Virtual methods always means performance overhead. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Java/J2EE Openings in RTP, NC
    ... JSP, EJB, DAO Developer ... An abstract class is declared with the keyword "class" and is an implementation, i.e., its methods can contain bodies. ... An interface is a declaration of public method signatures which taken together represent a type with a defined contract for interaction with other types. ... A "Type 1" JDBC driver is a bridge to an ODBC driver which in turn interacts with the data store. ...
    (comp.lang.java.programmer)
  • Re: Abstract class or interface?
    ... >derived classes can only inherit one abstract class. ... The interface properties/methods have no implementation. ... and rotate "things" along all three X, Y, and Z coordinate axis. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: public interface method Id rather not be
    ... > If I use an interface internally for my application, ... > I have a validation method which ordinarilly would be private. ... class can be extended by an inner class, ... method that returns the abstract class type when it creates ...
    (comp.lang.java.programmer)
  • Re: Abstract class or interface?
    ... I try to make the decision based on the relationship of the derived class to the base class. ... If the derived class "can act like" the type of the base class, I'd lean towards an interface. ... I understand the abstract class can have implementation in its methods and derived classes can only inherit one abstract class. ...
    (microsoft.public.dotnet.languages.csharp)