Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

oveloading doubt

 
raja reddy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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.
 
Shahnawaz Shakil
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • 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?
 
Rajkamal Pillai
Ranch Hand
Posts: 445
1
Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
I dont want overloading definition.I need reason other than that.Please help?
 
Campbell Ritchie
Sheriff
Pie
Posts: 48985
60
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic