From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a270a1fc28d4f812 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-07-05 13:02:07 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!snoopy.risq.qc.ca!torn!newsfeed.telusplanet.net!peer1-sjc1.usenetserver.com.MISMATCH!ps01-sjc1!news.webusenet.com!pd2nf1so.cg.shawcable.net!residential.shaw.ca!news1.calgary.shaw.ca.POSTED!not-for-mail X-Trace-PostClient-IP: 24.80.253.172 Sender: stephen@anakin Newsgroups: comp.lang.ada Subject: Re: OOD in Ada? References: <3d135676$0$8511$cc9e4d1f@news.dial.pipex.com> <3d1870b0$0$8507$cc9e4d1f@news.dial.pipex.com> From: stephen@dino.dnsalias.com (Stephen J. Bevan) Message-ID: Organization: just me at home X-Newsreader: Gnus v5.7/Emacs 20.7 Date: Fri, 05 Jul 2002 20:02:06 GMT NNTP-Posting-Host: 24.69.255.206 X-Complaints-To: abuse@shaw.ca X-Trace: news1.calgary.shaw.ca 1025899326 24.69.255.206 (Fri, 05 Jul 2002 14:02:06 MDT) NNTP-Posting-Date: Fri, 05 Jul 2002 14:02:06 MDT Xref: archiver1.google.com comp.lang.ada:26886 Date: 2002-07-05T20:02:06+00:00 List-Id: "David Crocker" writes: > Let me give you and others who have replied to my posting a real example of > an OO system where the "withing" problem occurs and I can't see an easy way > out of it. > > A compiler is being written. The compiler has to know about objects of class > Expression and Statement. Each of these is actually an abstract class with > many descendents (because there are many types of expression etc.). There seems to be two schools of thought about how best to structure a compiler :- * The "OO" way in which a base class is defined for various syntactic elements such as Expression and Statement and then subclasses are defined for specific instances such as IfStatement, ... etc. * The "old" way by defining a record for any syntactic units of interest and use case to cover variants. The "OO" way has an advantage if your implementation strategy is fixed but the language is changing since you can add new nodes without disturbing other code: just subtype and implement the required methods. The "old" way has an advantage if your language is fixed but your implementation strategy is not i.e. you may start out with some strategy and then realise that an extra pass could be used to do some othe sort of analysis/optimisation. That's because you can add a new phase without having to touch the nodes or the other phases (just the code where you plug the new phase in). >From your example it isn't clear to me which situation you are in, though statistically I would guess you have a fixed language. In that case I'd just stick with the "old" way of doing things and avoid classes completely. Some recommend sticking with the "OO" style but using some flavour of visitor to avoid having to touch so many classes should a new phase need to be added. However, it isn't clear to me how this is an improvement over the "old" way of doing things. This is probably not the answer you are looking for but it is how I'd solve your problem.