Hi,
I've started to learn more about overriding and overloading.
I think I understand how they work and I understand what makes a method signature.
However, what I don't understand is the point, or the usefullness. I cannot see the advantages, and hoped someone might clear things up...
As methods are executed by Java based on their message signature, if I want to add an argument to a method, this changes its signature, so now any other objects which use the modified method would break, as the signaure has changed and the message sends are no longer valid.
How is that helpfull or usefull. All other languages I have used you have one function/subroutine and the arguments can be optional, which makes things nice and simple and easy to work with.
In Java however if you want to alter a method and add a new parameter, without breaking other classes using that method, you have to overload the method, by creating another one which allows the new argument creating a new method signature.
So now you have to duplicate code that's already been written, just so I can add a new paramerter and a few extra lines of code to a method. sounds crazy to me, where is 'code reuse' practices there?
On top of this, if I want to override a method, and the programmer has writen 3 method signatures to a specific method name I now have to create 3 method signatures to override them, yet again causing code bloat and not following 'code reuse' practices.
Perhaps I'm missing something, or have missunderstood the course material, but if I understand method signatures, overriding and overloading, in terms of the way it works, then I don't get it, I find it cumbersome and could be a real nightmare to work with.
So any advice unravelling the usefullness and purpose of this behaviour is much appreciated.
1DMF.
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Google Rank Extractor -> PERL v1.5 beta (FusionCharts)
I've started to learn more about overriding and overloading.
I think I understand how they work and I understand what makes a method signature.
However, what I don't understand is the point, or the usefullness. I cannot see the advantages, and hoped someone might clear things up...
As methods are executed by Java based on their message signature, if I want to add an argument to a method, this changes its signature, so now any other objects which use the modified method would break, as the signaure has changed and the message sends are no longer valid.
How is that helpfull or usefull. All other languages I have used you have one function/subroutine and the arguments can be optional, which makes things nice and simple and easy to work with.
In Java however if you want to alter a method and add a new parameter, without breaking other classes using that method, you have to overload the method, by creating another one which allows the new argument creating a new method signature.
So now you have to duplicate code that's already been written, just so I can add a new paramerter and a few extra lines of code to a method. sounds crazy to me, where is 'code reuse' practices there?
On top of this, if I want to override a method, and the programmer has writen 3 method signatures to a specific method name I now have to create 3 method signatures to override them, yet again causing code bloat and not following 'code reuse' practices.
Perhaps I'm missing something, or have missunderstood the course material, but if I understand method signatures, overriding and overloading, in terms of the way it works, then I don't get it, I find it cumbersome and could be a real nightmare to work with.
So any advice unravelling the usefullness and purpose of this behaviour is much appreciated.
1DMF.
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Google Rank Extractor -> PERL v1.5 beta (FusionCharts)