I'm not understanding you. It sounds as though the arguments you pass to these two functions would be fixed -- i.e., the first one would always want 1 and 2, and the second one 1 and 3. So why not just have one method, and take action based on the values of the arguments with an "if" statement?
Hi, Jigar. It sounds like you don't really need overloaded functions unless the internal algorithm is different. If it is different, and if you must have overloaded functions, then I suggest converting the first of those parameters to a long. It's kind of a strange solution, though, because you would also need to convert the value to a long. So that will give you two overloaded functions total. [ November 17, 2004: Message edited by: Anton Golovin ]
Anton Golovin (email@example.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
Think about it. A programmer has to call your "findRecord()" method. He wants to call it with two numbers, 34 and 57. He knows, though, what sort of lookup he wants to do, right? I mean, he knows that 34 is the f2 value and 57 is the f3 value. I don't think there's any reason why he would object to having to express this knowledge; i.e., don't overload the methods, but encode the purpose of each method in its name.
On the other hand, Pradeep's suggestion (which he meant as a joke, I think) leads you to another solution that does allow overloading; very crudely, it looks like this:
Then you can call
RecordManager.getRecord(new F1(34), new F3(57))
and get the right overload. But personally, I'd prefer the non-overloaded version myself! [ November 18, 2004: Message edited by: Ernest Friedman-Hill ]
Here's another solution, which I think is slightly better than my earlier suggestion using reflection. This one creates a RecordSearch class, and the the Record simply checks itself agaist the record search class. Quite simple. You could either construct the RecordSearch objects the way I did in the code, or (more likely, especially if there are more than 5 fields), take a couple of lines and build it how you see fit, like
Anyway, here's the code to do this:
[ November 18, 2004: Message edited by: Joel McNary ]
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
posted 13 years ago
third mind blowing solution of the day.
i am really surprised that u have gone to such gr8 lengths to convey ur point.
thanks a lot for it.
but my problem is :
valid searches are "f1,f2" "f1,f3" and "f2,f4" only rest all searchs are invalid in the first place,
do if i do something like
and then call getRecord() then this call should fail. cause business logic doesnot allow to fetch a record only "f1,f4"
so now inorder to restrict i'll have to add the check, which will throw a runtime exception, if arguments are not correctly specified.
i'll have to document the correct permutations , which is worst than long function names.