Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: What advantages to overload procedure and function identifiers?
|
Posted: Mar 17, 2002 2:41 PM
|
|
Sounds like you are talking about Pascal or C++.
Method overloading is just a convenience. It allows you to keep things more concise, terse and succinct while avoiding copious repetitive redundancies. In short, it is syntactic candy -- which is not a bad thing as long as you floss regularly. For instance, with overloading, you can simply do the following:
System.out.println( 32 );
System.out.println( 33.33 );
System.out.println( "Wasn't that fascinating?" );
However, without overloading, you'd need to do this:
System.out.printInt( 32 );
System.out.println(); // Still need the new lines.
System.out.printDouble( 33.33 );
System.out.println();
System.out.printString( "Wasn't that fascinating?" );
System.out.println();
Or something like that. Or at the very least, you'd need to do something like this:
System.out.println( Integer(32).toString() );
System.out.println( Double(33.33).toString() );
System.out.println( "Wasn't that fascinating?" );
Overloading is also very convenient for constuctors, where you often want to be able to construct your object with different types of information. For instance, the FileInputStream can be constructed with a File, a String or a FileDescriptor object.
|
|