The Artima Developer Community
Sponsored Link

Java Answers Forum
Abstract Classes vs Interfaces

4 replies on 1 page. Most recent reply: Aug 12, 2003 10:19 PM by Michael Geisler

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Michael Rosenthal

Posts: 1
Nickname: mike1111
Registered: Aug, 2003

Abstract Classes vs Interfaces Posted: Aug 11, 2003 7:00 PM
Reply to this message Reply
Advertisement
I am looking for some help around why I would use an abstract class instead of an interface. Preferable list the answers as pro/con.


neelakkannan

Posts: 1
Nickname: snkannan
Registered: Aug, 2003

Re: Abstract Classes vs Interfaces Posted: Aug 12, 2003 1:25 AM
Reply to this message Reply
in interface all the methods are abstracts..but in abstract
class not the case..

with regards
snk

Lakhdip Nagra

Posts: 3
Nickname: lakhdip
Registered: Aug, 2003

Re: Abstract Classes vs Interfaces Posted: Aug 12, 2003 4:08 AM
Reply to this message Reply
I have sometimes wondered that too, but I usually stick to the rule where I use an abstract class as a bit of a class, in that I know what some of the implementation is going to be and put those bits in and the rest of the stuff leave to be added in by subclasses.

I use interfaces just where I want to define what set of operations will be available, so for example, if I'm working on a group project, I can agree the interface to say a Clock object with a friend and they can implement it while I can write the code that uses it and when we finish, it should work fine.

Hope that helps in some way,

David

Posts: 150
Nickname: archangel
Registered: Jul, 2003

Re: Abstract Classes vs Interfaces Posted: Aug 12, 2003 4:29 AM
Reply to this message Reply
Abstract Classes:
- Can contain instance variables.
- Can contain methods with an implementation.
- Can contain private/protected methods.

Interfaces:
- Can only contain public static final variables.
- Can only contain public abstract methods (no implementation).

Michael Geisler

Posts: 2
Nickname: goosey
Registered: Jul, 2003

Re: Abstract Classes vs Interfaces Posted: Aug 12, 2003 10:19 PM
Reply to this message Reply
Or you could use both.

Define an interface and partially implement it with an
abstract class - then you can give the users of your type
a choice - fully implement the interface themselves or extend the abstract class and only override the methods they need
to...Generally I think any type you define that you expect
to be sub-classed by other users should be defined as an interface first at the very least

Flat View: This topic has 4 replies on 1 page
Topic: jdblist refreshing Previous Topic   Next Topic Topic: basic ftp query

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use