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

oveloading doubt

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suppose you have an abstract class, and two concrete implementations. If you use your one method per parameter name idea, e.g. :

you need to explicitly code the logic that calls one method or the other. Replace this with:


Now you can blindly call the doStuff method and the right one will be called.
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well overloading simply let us reuse the same method name in the class. How useful this thing is, may be a matter of perception. But when you have a huge set of API then using the same name for same type of functions make sense. For example consider a function calculateArea(). This funcion should be overloaded depending upon the fact if we are calculating the area of a circle or a rectangle or any other shapy. Is it not a nicer way that the function name is always calculateArea() because this function is anyway calculating the area no matter what the shape is?
 
Ranch Hand
Posts: 479
1
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Overloading and overriding are two ways of implementing one of the basic concept of OOPS principles namely, polymorphism. I remember studying way back that the idea behind polymorphism was the same form for different uses. The main advantage of overloading can be qualified as improving the readability. Just consider a scenario where you are coding a calculator application where you have to perform various mathematical operations on different kinds of arguments. Would it not be better to have a single add()/subtract().... that takes advantage of overloading to perform the same operation for different arguments than having multiple addInteger()/addFloat().... etc? That said I do agree it improves the readability and also feel makes the code more elegant and maintainable. I am of the opinion that given a particular requirement anyone can write the code and get it to work but the real challenge is in writing code that is readable, easy to understand and to maintain (Keep in mind that more often than not the code one writes may have to be maintained by somebody else). As you mentioned the overhead on the compiler caused by overloading, I am of the view that would be minuscule as opposed to the neatness and structure it provides.

Cheers,
Raj.
[ August 12, 2008: Message edited by: Raj Kamal ]
 
raja reddy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your reply.if you dont mind,can you please elaborate it.
 
raja reddy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont want overloading definition.I need reason other than that.Please help?
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rajaraja reddy:
I dont want overloading definition.I need reason other than that.Please help?

You already have replies; please explain what you don't know so we can help you.
reply
    Bookmark Topic Watch Topic
  • New Topic