This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Function Overloading  RSS feed

 
Anshika Gehani
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I am preparing my project on Airlines Booking but am unable to use one of the concepts that are to be implemented . That concept is function Overloading . Can anyone please suggest me as to where exactly in My Project on Airlines Booking on Blue J can I use Function Overloading.Please suggest some ideas . The project is basically about booking some tickets.

regards,
Anshika
 
Tim Cooke
Marshal
Posts: 3869
233
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know what function (method) overloading is?
 
Anshika Gehani
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Cooke wrote:Do you know what function (method) overloading is?

Obviously i know what function overloading is . It is the process of using various functions with the same name but with different type or different no. of parameters. I just need an idea where exactl can i use it in my project .

Regards,
Anshika
 
Tim Cooke
Marshal
Posts: 3869
233
Clojure IntelliJ IDE Java
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not really obvious. Internet forums have come a long way but telepathy hasn't made it onto the feature list just yet.

It's difficult to provide a definitive recommendation for you as I have no idea what your project looks like. I'll hazard a guess though with this example:


 
Ahmed Bin S
Ranch Hand
Posts: 385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Cooke wrote:Not really obvious. Internet forums have come a long way but telepathy hasn't made it onto the feature list just yet.

It's difficult to provide a definitive recommendation for you as I have no idea what your project looks like. I'll hazard a guess though with this example:




Judging from the question, I very much doubt the OP has started creating classes for things like Airport and AirportCode. So probably more appropriate would be


 
Stephan van Hulst
Saloon Keeper
Posts: 7804
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using Strings to represent non-textual data is *never* appropriate. You can easily create stubs if you haven't fully fleshed out your classes yet.
 
Ahmed Bin S
Ranch Hand
Posts: 385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:Using Strings to represent non-textual data is *never* appropriate. You can easily create stubs if you haven't fully fleshed out your classes yet.


I disagree. It is apparent from the question that the OP is a beginner who is just getting to grips with the basics of Java and that this is a homework assignment for beginners. The OP most likely hasn't been introduced to OOD yet, and therefore, I think for a homework assignment it is perfectly appropriate to use Strings to represent non-textual data.

 
Stephan van Hulst
Saloon Keeper
Posts: 7804
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you can create a class that contains overloaded methods, you can create class stubs that act as a placeholder for whatever it is you want to return. These class stubs don't have to be fully thought out. I think it's best to teach people as soon as possible that Strings are evil.
 
Ahmed Bin S
Ranch Hand
Posts: 385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:If you can create a class that contains overloaded methods, you can create class stubs that act as a placeholder for whatever it is you want to return. These class stubs don't have to be fully thought out. I think it's best to teach people as soon as possible that Strings are evil.


When I was taught C++ I was taught about function overloading way before I was even taught what a class is. Now obviously in Java people would be taught what a class is right at the beginning, but I would still strongly suspect that they would be taught about the syntax of the language first before they were exposed to OOD. If this is the case for the OP, if the purpose of the homework is to simply see that the students understand the syntax of the language and can call functions to do things, then I don't see the purpose of complicating things further by introducing classes for Airport etc.

Of course, if the OP has been exposed to OOD, then it's completely different.
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahmed Bin S wrote:When I was taught C++ I was taught about function overloading way before I was even taught what a class is.

And that's because it's an integral part of the language. In Java it isn't - on purpose. Indeed function (or operator) overloading is basically non-existent; and IMO method overloading is something, in general, to avoid if you can.

Now obviously in Java people would be taught what a class is right at the beginning

You have no choice, since you must create a class to run a program.

but I would still strongly suspect that they would be taught about the syntax of the language first before they were exposed to OOD.

True, but I think some of us here would say that many courses put too much emphasis on syntax, and not enough on the OO side - which results in beginners basically writing C/C++ (or procedural) code until they've been given the "Java mind-meld".

Not being a teacher, I don't know exactly what the answer is; but one thing I always bang on about to beginners is to think about what, not how. And I agree so strongly with Stephan about not using Strings inappropriately, that I actually wrote a page about it.

If this is the case for the OP, if the purpose of the homework is to simply see that the students understand the syntax of the language and can call functions to do things, then I don't see the purpose of complicating things further by introducing classes for Airport etc.

I don't agree. That's simply mollycoddling and reinforcing bad practises as habit.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!