I'm not new to OO programming, but I ran into a mysterious situation. I was provided with a program for work and expansion, but previous developers did not seem to feel comfortable with OO, it seems they either had background C or an incomprehensible understanding of OO. Now I do not suggest that I be a better developer, I just think that I can detect some common OO errors. The difficult task is how to change them.
In my case, I see a lot of things:
if (ret == 1) { out.print("yadda yadda"); } else if (ret == 2) { out.print("yadda yadda"); } else if (ret == 3) { out.print("yadda yadda"); } else if (ret == 0) { out.print("yadda yadda"); } else if (ret == 5) { out.print("yadda yadda"); } else if (ret == 6) { out.print("yadda yadda"); } else if (ret == 7) { out.print("yadda yadda"); }
ret is the value returned by the function in which all Exceptions are swallowed, and in the catch blocks, the above values are returned explicitly. Often, Exceptions are simply swallowed with an empty catch block.
Obviously, swalllowing exceptions are a poor development of OO. My question is about using return values. I believe that this is also wrong, but I think that using exceptions for the control flow is equally wrong, and I cannot think of anything to replace the above in the correct OO manner.
Your entry please?
source share