• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

when to use abstract and interfaces in our project

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

i am having knowledge regarding abstarct and interfaces.
abstract class contains concrete methods and also abstract methods. and also abstract methods are not going to initialize.
but in interfaces all are abstract methods and variables by default final static.

but i want to know when we will use abstract and interfaces in our real time project.

please suggests your ideas.

with regards,
Y.Rama krishna
 
Ranch Hand
Posts: 44
1
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there

Read http://java.sun.com/docs/books/tutorial/java/IandI/abstract.html it might help abit.

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

Originally posted by yekkala krishna:

but i want to know when we will use abstract and interfaces in our real time project.



Of course there's not an exact and precise rule...much it's up to designers' choices..

I can give you my "rules of a thumb":
  • Usually, after a refactor, when grouping common code in a new "ancestor class" you come up with a class you cannot associate to a precise logical entity and therefore you want to inhibit people from instantiating it
  • When "ancestor class" code needs to call methods which have implementations which have absolutely to be defined in the extending class. Marking a method as abstract make the implementor more conscious of what they MUST do than simply defining a default implementation which CAN then be overridden
  •  
    His brain is the size of a cherry pit! About the size of this ad:
    Gift giving made easy with the permaculture playing cards
    https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
    reply
      Bookmark Topic Watch Topic
    • New Topic