From: Barry K. <bk...@in...> - 2002-11-19 16:16:42
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"> <title></title> </head> <body> <blockquote type="cite" cite="mid...@ba..."> <blockquote type="cite"> <pre wrap="">The class I have been using to learn mocksobjects: public interface Position { int getQuantity(PositionBucketType bucketType, PositionTimeType timeType); int getQuantity(LongShort longShort, CreditType creditType, PositionTimeType timeType); .... } Different components of our system know different aspects of a position. The two methods above allow each to access the quantities polymorphically without any ifs or switches. </pre> </blockquote> <pre wrap=""><!----> Java does not dispatch methods polymorphically based on runtime argument types. If your code is calling overloaded methods you don't need ifs and switches.</pre> </blockquote> <br> I was not refering to polymorphism at the overloaded method level, but the ability to not have to do:<br> <br> int quantity<br> if ( bla bla) {<br> getLongCashOvernightQuantity();<br> else if (bla bla) {<br> get ShortCashOvernightQuantity();<br> else if (bla bla)<br> get LongMarginDaytradeQuantity();<br> else if (bla bla)<br> ...<br> <br> (Remember, you asked why overloaded methods were necessary at the interface level. The above is why).<br> <br> <br> </body> </html> |