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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: A bad counterintuitive behaviour of Ada about OO Date: Mon, 11 Aug 2014 09:41:09 +0200 Organization: cbb software GmbH Message-ID: <2e3dyovp6wty.myprjpgzi2uy$.dlg@40tude.net> References: <932kntuq5rrr.8sumwibqrufn.dlg@40tude.net> <1ohy7vnbntskq$.h139ov04mlxu$.dlg@40tude.net> <536e35d6-f1de-4917-9300-26d78686eaf2@googlegroups.com> <1w3wuhu3d4nxi$.qluzbi0gtlxx$.dlg@40tude.net> <2extr7bydwfw.tcda12f9xnq9.dlg@40tude.net> <4a3996f3-666e-404a-ad8b-ff1832751787@googlegroups.com> <19297tmx9dt9q.1p2p4i0odtkyw.dlg@40tude.net> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: yj8+JIQUMOEawvIM7K49kA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:21655 Date: 2014-08-11T09:41:09+02:00 List-Id: On Sun, 10 Aug 2014 13:55:00 -0700 (PDT), Maciej Sobczak wrote: > W dniu sobota, 9 sierpnia 2014 18:48:33 UTC+2 użytkownik Dmitry A. Kazakov napisał: > >> The example does not make any sense. Since it would be impossible to >> dispatch on Make without knowing the type of the outcome. > > The example does not make any sense, because it is not supported by Ada. > It does make perfect sense in those languages that support it. Nope, it would not work in any language, unless you redefine the word dispatching as you tried with covariance. There is no dispatching when types are known. >> Factory pattern in Ada is this: >> >> type Factory is abstract tagged null record; >> >> function Make (F : not null access Factory) return A'Class; >> >> Then you do: >> >> type A_Factory is new Factory with ... >> >> override function Make (F : not null access A_Factory) return A'Class; >> >> type B_Factory is new Factory with ... >> >> override function Make (F : not null access B_Factory) return A'Class; >> >> And in case you do know the result type no factory object is ever needed, >> because you just do: >> >> X : A; > > Wrong. Or rather half-way right. I also want to do this: > > Y : B := Make (B_F); Where is a problem? Do this (in another package): not overriding function Make (F : not null access B_Factory) return B; Observe: not overriding. Which is not needed either, because: Y : B; -- That is >> It cannot work in any language, even if full MD were supported, which would >> make your example possible. The pattern is just useless. > > Useless? Yes, useless. If you know all types involved you call a specific subprogram or simply declare the object. Work done. Factories are used *only* when types are unknown in advance. Or, in the case of Ada, due to the language design bug that does not allow to pass parameters to Initialize. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de