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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a5d76152c5cb8790 X-Google-Attributes: gid103376,public From: Francois Godme Subject: Re: class-wide objects Date: 1998/12/09 Message-ID: <366EE6BA.7D586BDD@magic.fr>#1/1 X-Deja-AN: 420568635 Content-Transfer-Encoding: 7bit References: <366B1190.C8142307@magic.fr> X-Client: Magic On Line [unknown@ppp10-227.magic.fr] Content-Type: text/plain; charset=us-ascii Organization: very little Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1998-12-09T00:00:00+00:00 List-Id: Matthew Heaney writes: > Your type will probably have to have some sort of dispatching clone method: > > generic > ... > package Stacks is > > type Stack_Type is tagged limited private; > > type Stack_Access is access all Stack_Type'Class; > > function Copy (Stack : Stack_Type) return Stack_Access; > ... > end Stacks; > > which you'd use something like: > > procedure Op (Stack : in Stack_Type'Class) is > > Copy_Of_Stack : Stack_Access := Copy (Stack); > > begin The clone method is inventive but it is a very odd method in the sense that when you inherit it, it is always wrong for you. So, you have to redefine it. Usually, when you redefine a method, you call the inherited method on the superclass part of you and finish the job yourself for the added part. Here, the inherited method is not reusable because it clones objects of your superclass not of yourself. You are the only one able to clone yourself as your father knows nothing of you. You are not forced to override this method by the language like the language would do for an abstract method, so you can forget to do it. You are on your own. It's like a genetic disease that affects all generation. It can be cured easily in one generation but the next generation will be affected the same way. The disease cannot be stopped. It reappears from generation to generation. Some generation are sane, some are are sterile (they cannot reproduce themselves, they reproduce as their parents.) The cure is always the same. It can be as simple as an Emacs Macro. function Copy (Stack : Stack_Type) return Stack_Access is use type Ada.Tags.Tag; begin -- tries to be kind with sick children if Stack_Type'Class (Stack)'Tag /= Stack_Type'Tag then raise ...; -- Is that kindness ? I think it's better than return null. -- The family takes on responsabilities for its sick -- children. else return new Stack_Type; end if; end Copy; The attribute I was asking for does almost the same thing as the clone method but without the associated problems.