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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.236.111.106 with SMTP id v70mr12850467yhg.21.1407743892985; Mon, 11 Aug 2014 00:58:12 -0700 (PDT) X-Received: by 10.140.20.151 with SMTP id 23mr9830qgj.13.1407743892965; Mon, 11 Aug 2014 00:58:12 -0700 (PDT) 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!news.glorb.com!v10no6134885qac.1!news-out.google.com!b3ni24360qac.1!nntp.google.com!j15no6205060qaq.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 11 Aug 2014 00:58:12 -0700 (PDT) In-Reply-To: <2e3dyovp6wty.myprjpgzi2uy$.dlg@40tude.net> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=195.182.34.254; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S NNTP-Posting-Host: 195.182.34.254 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> <2e3dyovp6wty.myprjpgzi2uy$.dlg@40tude.net> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <6c67704a-d399-433d-bd8e-4566e79defaf@googlegroups.com> Subject: Re: A bad counterintuitive behaviour of Ada about OO From: Maciej Sobczak Injection-Date: Mon, 11 Aug 2014 07:58:12 +0000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:21657 Date: 2014-08-11T00:58:12-07:00 List-Id: W dniu poniedzia=C5=82ek, 11 sierpnia 2014 09:41:09 UTC+2 u=C5=BCytkownik D= mitry A. Kazakov napisa=C5=82: > 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. OK, so you still don't get it. The (potential) dispatch is on the factory t= ype: procedure Use_Whatever_Factory (F : in Factory'Class) is P : Product'Class :=3D F.Make_Product; begin -- ... end; Now you have dispatch on the factory type. Of course, I still want all the specific calls work, too, that's why the re= turn type cannot be Product'Class, otherwise I will be forced to cast types= . In other words, this has to work as well: procedure Use_Specific_Factory (F : in Specific_Factory) is SP : Specific_Product :=3D F.Make_Product; begin -- ... end; And there is no way to make *both* work in Ada. You can get one or the othe= r but not both. > Where is a problem? Do this (in another package): >=20 > not overriding > function Make (F : not null access B_Factory) return B; >=20 > Observe: not overriding. And this is where your idea breaks down. The Make operation *must* be overr= iding, otherwise I will not be able to use Factory'Class. > > Useless? >=20 > Yes, useless. If you know all types involved you call a specific subprogr= am > or simply declare the object. Work done. I might not know the specific factory type. That's the whole point of all c= reational design patterns, which I have mentioned several times already. > Factories are used *only* when types are unknown in advance. Not only. I might want to use specific factory from the hierarchy of factor= ies, too. The OOP does not force me to use class-wide types only. --=20 Maciej Sobczak * http://www.msobczak.com * http://www.inspirel.com