Comparing abstract base class and Interface

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony Johansson

    #1

    Comparing abstract base class and Interface

    Hello!

    If you compare an abstract baseclass and an Interface and you only look at
    the datamembers what exactly is that
    differ or is the same. For example can you have datamember in both or just
    in one of these.

    //Tony


  • Casper B

    #2
    Re: Comparing abstract base class and Interface

    It's a good question, one that everyone ask themselves when learning Java.

    You have probably heard the saying "Program to interfaces, not
    implementations " countless times. In this regard, an interface does not
    qualify to just the java interface construct, but covers also abstract
    classes.

    One clear disadvantage of an abstract class, is that naturally you have
    already used your single inheritence option. However, you often meet
    abstract base classes in frameworks where some default behavior is
    needed (event handling, required initiations etc.).

    As you probably know, interfaces are Java's way of providing a multiple
    inheritance feature. But the feature is implemented through composition
    rather than inheritance. This is where a bunch of well-defined design
    patterns like Strategy and Decorator comes to play.

    /Casper

    Comment

    Working...