home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / modula3 / 909 < prev    next >
Encoding:
Internet Message Format  |  1992-09-14  |  2.2 KB

  1. Path: sparky!uunet!pmafire!news.dell.com!swrinde!sdd.hp.com!nigel.msen.com!spool.mu.edu!darwin.sura.net!Sirius.dfn.de!Urmel.Informatik.RWTH-Aachen.DE!schumann!pk
  2. From: pk@rwthi3.informatik.rwth-aachen.de (Peter Klein)
  3. Newsgroups: comp.lang.modula3
  4. Subject: Re: Constructors in Modula-3
  5. Message-ID: <1992Sep14.150057.4225@Urmel.Informatik.RWTH-Aachen.DE>
  6. Date: 14 Sep 92 15:00:57 GMT
  7. References: <ANDRU.92Sep14011727@concerto.lcs.mit.edu>
  8. Sender: news@Urmel.Informatik.RWTH-Aachen.DE (Newsfiles Owner)
  9. Reply-To: pk@rwthi3.informatik.rwth-aachen.de
  10. Organization: Lehrstuhl fuer Informatik III, RWTH Aachen, Germany
  11. Lines: 38
  12. Nntp-Posting-Host: schumann
  13.  
  14. An obvious solution (though not very elegant) to the constructor problem is
  15. to have an "initialized" flag in the object. This can be set to FALSE by the
  16. default initialization. Every method should check this flag and either raise
  17. an exception if the flag is unset, or it can dynamically init the object at
  18. the first use. Especially the last solution makes NEW act like a constructor,
  19. since the actual init method is not exported.
  20.  
  21. Now, if you don't like this, I think we should handle the problem in a more
  22. general way. Your suggestion might work for constructors, but at the cost
  23. of introducing pretty much new syntax. This overhead could be reduced
  24. dramatically if we think of constructors as class methods, i.e. methods
  25. which can be applied to non-existing objects. This might look something
  26. like
  27. TYPE A = OBJECT
  28.            <fields>
  29.          CLASS
  30.            <class methods>
  31.          METHODS
  32.            <object methods>
  33.          OVERRIDES
  34.            <class & object method overrides>
  35.          END;
  36. Maybe the distinction between class and object methods could be dropped
  37. altogether; I'm not sure if I'd like this.
  38.  
  39. In this case, NEW would loose it's status as standard operator and would
  40. become a default for a class constructor. Any new class declaration could
  41. override this NEW method by doing a NEW on the superclass and then perform
  42. initializations on the object fields.
  43.  
  44. Peter
  45. ---
  46. Peter Klein                        E-Mail: pk@rwthi3.informatik.rwth-aachen.de
  47. Lehrstuhl fuer Informatik III      Tel.: +49/241/80-21320
  48. Ahornstrasse 55                    Fax.: +49/241/80-21329
  49. RWTH Aachen
  50. D-5100 Aachen
  51. Germany
  52.