The Artima Developer Community
Sponsored Link

Java Answers Forum
Difference between abstract class and interface in the desingn perspective

5 replies on 1 page. Most recent reply: Aug 12, 2004 3:28 AM by Kirtish

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 5 replies on 1 page
Vijay Kumar vemuri

Posts: 3
Nickname: vardhani
Registered: Jun, 2004

Difference between abstract class and interface in the desingn perspective Posted: Jun 11, 2004 6:27 AM
Reply to this message Reply
Advertisement
hi
i want to know the when to use abstract class and interface in the design perspective
please don't go with the regular answers


twc

Posts: 129
Nickname: twc
Registered: Feb, 2004

Re: Difference between abstract class and interface in the desingn perspect Posted: Jun 11, 2004 8:11 AM
Reply to this message Reply
I don't know what the "regular" answers are, but here is an explanation that makes some sense to me.

Let's start with abstract classes. If you look at the Component class you will see that it is abstract. All of its descedants share certain attributes, such as the ability to be visible on the screen, having a background and foreground color, having a size and a position. They inherit these from their common parent the Component class.

On the other hand, when you look at an interface, such as the Comparable interface, you see that it is used with many different and disparate classes. For example, the String, Integer, and Date classes all implement the Comparable interface. Clearly, none of these classes are related to one another. But because they all have the methods required by the Comparable interface, they can be used as Comparable objects as well as objects of their native class. (Keep in mind, that String's cannot be compared to Integers or Dates, only other Strings.)

Think of the descendents of an abstract class being related by blood while implementers of an interface are related by marriage. If Bob Smith marries Tina Jones, and they go to the Smith family reunion, Bob will be genetically similar to other Smiths because his is a blood connection. Tina is now a Smith, but she doesn't share any genetic link because her connection is through marriage.

When you design, ask yourself if the connection can apply to disparate classes. If it can, use an interface. But if the connection is more innate, then use an abstract class.

tom

Shashank D. Jha

Posts: 68
Nickname: shashankd
Registered: May, 2004

Re: Difference between abstract class and interface in the desingn perspective Posted: Jun 11, 2004 8:41 AM
Reply to this message Reply
> hi
> i want to know the when to use abstract class and
> nd interface in the design perspective
> please don't go with the regular answers

Well, Nice question at all.

Basically if/ when u r doing system design you should use Interfaces, because this is what specifies the behaviour of parts of the system.

While implementing the interfaces (implementation design/strategy), you may have implementation class hierarchy wherein you may define an abstract class to provide default behaviour of deriving classses.

hope this helps.

regards,
Shashank

Vijay Kumar vemuri

Posts: 3
Nickname: vardhani
Registered: Jun, 2004

Re: Difference between abstract class and interface in the desingn perspect Posted: Jun 15, 2004 2:45 AM
Reply to this message Reply
thank u very much
Now i am clear with these two things
VijaY

Uma

Posts: 4
Nickname: chumma
Registered: Jun, 2004

Re: Difference between abstract class and interface in the desingn perspect Posted: Jun 15, 2004 10:21 AM
Reply to this message Reply
Good answer.I understood concepts

Kirtish

Posts: 2
Nickname: kparekh
Registered: Aug, 2004

Re: Difference between abstract class and interface in the desingn perspect Posted: Aug 12, 2004 3:28 AM
Reply to this message Reply
Twc, superb explanation. Thanks a lot.
Kirtish.

Flat View: This topic has 5 replies on 1 page
Topic: Reporting in Java Swing Apps Previous Topic   Next Topic Topic: create a checkbox bean

Sponsored Links



Google
  Web Artima.com   

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