Path: news.daimi.aau.dk!news-feed.inet.tele.dk!europa.clark.net!144.212.100.12!news.mathworks.com!solaris.cc.vt.edu!server.cs.vt.edu!not-for-mail From: siva@csgrad.cs.vt.edu (Siva Challa) Newsgroups: comp.lang.beta Subject: Re: Method overloading in BETA Date: 7 Nov 1997 21:25:10 GMT Organization: Virginia Tech Computer Science Lines: 84 Message-ID: <6400vm$tuo@server.cs.vt.edu> References: <63r2ti$qfq@server.cs.vt.edu> <3461A0F9.3752@marvin.informatik.uni-dortmund.de> NNTP-Posting-Host: csgrad.cs.vt.edu Xref: news.daimi.aau.dk comp.lang.beta:11286 In article <3461A0F9.3752@marvin.informatik.uni-dortmund.de>, Holger Tuerk wrote: >Hello, > >Siva Challa wrote: >> I am new to the BETA language. I have a general question. Is 'method >> overloading' allowed in BETA? > >If 'method overloading' means that different methods with the same name >are invoked depending on the number and types of the arguments you >passed, the answer is no. >You have to choose different designations for your patterns. > >Holger Thank you very much for your answer to my question on 'method overloading' in BETA. I have a follow up question on the same issue. Let me tell you a little bit about what I am trying to do before asking the question. I am trying to see if 'method overloading' can be faked with existing features of a language, if it does not support the 'method overloading' feature. For example, Modula-3 does not support method overloading. But, it has run time type checking. It has a common base class for all classes called 'REFANY'. You can typecast any class to this class and typecast it back. Modula-3 also supports default values for method arguments. Let me take an example ( I am using a pseudo code representation} let A, B, and C be classes. class A { methodF (b : B, c: C); methodF (c : C); } In languages like C++, I can invoke methodF with one argument or two arguments. The compiler can figure out which method to invoke depending on the arguments. If I want to have similar facility in Modula-3, I can use the following (again i am using a pseudo code syntax for simplicity) Class A { methodF_B_C(b : B, c: C); methodF_C(c : C); methodF(r : REFANY, c : REFANY := NIL) } Here methodF has a default value for the parameter c. So, we can call methodF with one argument or two arguments. In the one argument call, it assumes that the second argument value is NIL. In the implementation of methodF, I can check the type of the first argument, and then invoke the right method (methodF_B_C or methodF_C) by typecasting the arguments to their respective types. The implementation of methodF can look like the following pseudo code: 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)); } I hope I am able to explain it. Now, my question is, IS THERE ANY WAY IN THE BETA LANGUAGE TO FAKE 'METHOD OVERLOADING'. In Modula-3, I needed default values for arguments, runtime typechecking, and a common base class called REFANY. I don't know much about the language BETA. I am not able to figure out if I can do it in BETA too. Please let me know if my example is clarifying my question. I would appreciate any help with the answer. Thanks again. Siva siva@vt.edu