home *** CD-ROM | disk | FTP | other *** search
- 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
- From: pk@rwthi3.informatik.rwth-aachen.de (Peter Klein)
- Newsgroups: comp.lang.modula3
- Subject: Re: Constructors in Modula-3
- Message-ID: <1992Sep14.150057.4225@Urmel.Informatik.RWTH-Aachen.DE>
- Date: 14 Sep 92 15:00:57 GMT
- References: <ANDRU.92Sep14011727@concerto.lcs.mit.edu>
- Sender: news@Urmel.Informatik.RWTH-Aachen.DE (Newsfiles Owner)
- Reply-To: pk@rwthi3.informatik.rwth-aachen.de
- Organization: Lehrstuhl fuer Informatik III, RWTH Aachen, Germany
- Lines: 38
- Nntp-Posting-Host: schumann
-
- An obvious solution (though not very elegant) to the constructor problem is
- to have an "initialized" flag in the object. This can be set to FALSE by the
- default initialization. Every method should check this flag and either raise
- an exception if the flag is unset, or it can dynamically init the object at
- the first use. Especially the last solution makes NEW act like a constructor,
- since the actual init method is not exported.
-
- Now, if you don't like this, I think we should handle the problem in a more
- general way. Your suggestion might work for constructors, but at the cost
- of introducing pretty much new syntax. This overhead could be reduced
- dramatically if we think of constructors as class methods, i.e. methods
- which can be applied to non-existing objects. This might look something
- like
- TYPE A = OBJECT
- <fields>
- CLASS
- <class methods>
- METHODS
- <object methods>
- OVERRIDES
- <class & object method overrides>
- END;
- Maybe the distinction between class and object methods could be dropped
- altogether; I'm not sure if I'd like this.
-
- In this case, NEW would loose it's status as standard operator and would
- become a default for a class constructor. Any new class declaration could
- override this NEW method by doing a NEW on the superclass and then perform
- initializations on the object fields.
-
- Peter
- ---
- Peter Klein E-Mail: pk@rwthi3.informatik.rwth-aachen.de
- Lehrstuhl fuer Informatik III Tel.: +49/241/80-21320
- Ahornstrasse 55 Fax.: +49/241/80-21329
- RWTH Aachen
- D-5100 Aachen
- Germany
-