Path: news.daimi.aau.dk!news-feed.inet.tele.dk!nntprelay.mathworks.com!news.pn.com!nntp.pn.com!main.Germany.EU.net!main.de.uu.net!Dortmund.Germany.EU.net!dortmund.de.uu.net!Informatik.Uni-Dortmund.DE!news From: Holger Tuerk Newsgroups: comp.lang.beta Subject: Re: Method overloading in BETA Date: Mon, 10 Nov 1997 10:52:58 +0100 Organization: CS Department, University of Dortmund, Germany Lines: 65 Message-ID: <3466D97A.1DD@marvin.informatik.uni-dortmund.de> References: <63r2ti$qfq@server.cs.vt.edu> <3461A0F9.3752@marvin.informatik.uni-dortmund.de> <6400vm$tuo@server.cs.vt.edu> NNTP-Posting-Host: marvin.informatik.uni-dortmund.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 3.0 (X11; I; SunOS 5.5.1 sun4u) CC: siva@vt.edu, htuerk00 Xref: news.daimi.aau.dk comp.lang.beta:11287 Hello Siva Challa, concerning faked method overloading, the strategy used in your examples can also be applied to BETA, but because BETA has no feature for default values, the length of the evaluation list of an enter part of a given pattern is always the same. Siva Challa wrote: > Class A { > methodF_B_C(b : B, c: C); > methodF_C(c : C); > methodF(r : REFANY, c : REFANY := NIL) > } In BETA, the REFANY object is simply called object, so the method will look like methodF: (# ... r,c: ^object enter (r[], c[]) ... #) Pay attention to the fact, the methodF must always be called with the assignment of two references, and that this _only_ works with references. If the assignment of NONE ist not meaningful in your problem domain, you can use the NONE reference to indicate an omitted parameter. > methodF(r : REFANY, c : REFANY := NIL) { > if (typeOf(r) is B) then > call methodF_B_C((typecast r to B), (typecast c to C)); > else if (typeOf(r) is C) then > call methodF_C((typecast r to C)); > } Analogously, you can use the comparison of qualifications. Let A and B be patterns (In your examples, you used C for the class and c for the variable. Remember that BETA is case-insensitive.). methodF: (# ... r, c: ^object enter (r[], c[]) do (if r## // a## then (r[], c[])->methodF_B_C // b## then r[]->methodF_C if) #) Not shown in this example: You have to check for NONE _before_ trying to compare the qualification of an object. As far as I know, you do not have to explicitly typecast. The compiler will insert a runtime qualification check and your program will abort if you made an erroneous assumption. If the compiler will not compile code like this, consider the qua pattern in betaenv. The use of this kind of method selection is discouraged. Better find different and _expressive_ names for the methodF_B_C and methodF_C patterns, because it will make your program more readable. This is possible, since the classic method overloading affects the behaviour only of the compiler. The fakes you provided have a much bigger functionality, because the actual type at runtime decides which procedure should be invoked. Using this for method overloading, you are programming something you do not really need. friendly yours, Holger