| Author |
abstract class vs interface ?
|
sam mon
Greenhorn
Joined: Mar 20, 2003
Posts: 2
|
|
|
when should i use abstract class rather than interface ? and when use interface rather than abstract class ?
|
 |
Andris Jekabsons
Ranch Hand
Joined: Jan 20, 2004
Posts: 82
|
|
Use interface when you don't need to provide ANY implementation. Use abstract class when you need to provide SOME implementation, but leave the rest unimplementated. The way I picture it is that interface just gives you most basic direction what your class should do. Abstract class implementats those directions, but doesn't do it fully - just becomes a "half-done" class (and there are situations when you'd need that).
|
 |
Lionel Badiou
Ranch Hand
Joined: Jan 06, 2005
Posts: 140
|
|
Hi Sam, * Use abtract classes for fundamentals concepts in your OO design. Implement abstract classes with basic and and common services of a class hierarchy. * Use Interface as "requirements class" for a process. Interfaces enable to describe what you will find at least in a class. For example, when a method need and Interface X instance to run, you don't care about what class instance you actually use, you only care about the fact that the instance you use meet the minimum requirements described in the interface X. Hope that could be useful, best regards,
|
Lionel Badiou
CodeFutures Software
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
|
See http://faq.javaranch.com/view?InterfaceVsAbstractClass
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
 |
|
|
subject: abstract class vs interface ?
|
|
|