• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

extends vs implements

 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anyone wanna take a crack at explaining the theoretical difference between extending an abstract class or implementing an interface?
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is good discussion on the subject in the first Chapter of 'Design Patterns' by Gama, helm, Jhonson, Vlissides. I qoute from the book
 
Qudsia Jaffery
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry about breaking this into two messages, however here is the qoute
"An objects class defines how the obect is implemented. The class defines the objects internal state and the implementation of its operations. In contrast an objects type only refers to its interface - the set of requests to which it can respond. An object can have many types and objects of different types can have the same type."
Some differences that I can think of are
An abstrct class may have some concrete method and some attributes
All methods of an interface need to be impemented, in the class that extends the interface
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Andrew,
There was a good
article in April 2001 issue of Javaworld. You might find it interesting and informative too.
-Ramesh
 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
There is one definition of abstract class that I can think of - If you are certain that the instance of class can ONLY be one of the subtypes instances then define that class as abstract.
Larman (Applying UML and Patterns) illustrates this with an example of Payment as an abstract class, since its instance can only be of Cash,Credit and Check types.
Another use of abstract class is in Template pattern - An abstract class contains a concrete method and another non-concrete/abstract methods.These abstract methods are implemented in the subtypes.In the abstract class, the non-concrete methods are called in the concrete method, i.e the basic template of what needs to be done is defined in the abstract class.
As regards interface, one definition which I can think of is instance of a class can't be predicted.The class could then be defined as an interface, where the concrete subtypes which implement this interface could act as different plug-ins.
Would also like to add, that when you extend a class, you are inheriting both the capability and responsibility of the superclass.However, when you implement the interface, you are only inheriting the responsibility of the supertype.
Hope this helps,
Sandeep
[This message has been edited by Desai Sandeep (edited June 28, 2001).]
 
reply
    Bookmark Topic Watch Topic
  • New Topic