• Post Reply Bookmark Topic Watch Topic
  • New Topic

abstract empty class  RSS feed

 
Swapna latha
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have seen in many of the codings written like



This abstract class is extended and i am not understanding whats the use of this ?

thanks

swapna
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swapna latha wrote:This abstract class is extended and i am not understanding whats the use of this ?

I don't understand the question. Are you asking why someone would write an abstract class?

Winston
 
Jan Hoppmann
Ranch Hand
Posts: 147
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:I don't understand the question. Are you asking why someone would write an abstract class?

Winston


I think his question is why someone would write an empty abstract class.
It might be used the same as a marker interface, which is empty, too - so just to mark it as a special type.
 
Naresh Katam
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swapna

Please look into the below post. May be it gives the information that you are looking

http://www.coderanch.com/t/411094/java/java/Empty-abstract-classs-Empty-interface

@Naresh
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Yes, I think that is a useful post.
 
Naresh Katam
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ritchie

I thought of giving color to URL, by mistake it applied to entire text.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swapna

It sounds as if someone wanted a base class for a particular object model when perhaps, like others have stated, they actually wanted a marker interface.

Does an empty abstract class satisfy the following:
- polymorphism
- code reuse
- encapsulation
In all cases, the answer is no.

In summary, it is ugly code and a poor design but if it isn't breaking anything, it is probably advisable to leave it alone. Perhaps, ask the original author why they designed it this way? Did they javadoc their decision?
 
Alex Theedom
Author
Ranch Hand
Posts: 77
5
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A empty abstract class can be used to group together classes. This is in order to show some intent and to ensure the single responsibility principle that a class should have just one purpose.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alex

The example you give uses an interface, not an empty abstract class.

Alex Theedom wrote:A empty abstract class can be used to group together classes

You use packages for that.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Naresh Katam wrote:Ritchie

I thought of giving color to URL, by mistake it applied to entire text.
URLs colour themselves automatically. Use the URL button on your posts, and you can use the preview button beneath the post window to view your post before submitting it.
 
Swapna latha
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all.

swapna
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!