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.66.159.228 with SMTP id xf4mr3584402pab.24.1407704100624; Sun, 10 Aug 2014 13:55:00 -0700 (PDT) X-Received: by 10.140.33.203 with SMTP id j69mr496782qgj.2.1407704100576; Sun, 10 Aug 2014 13:55:00 -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!h18no17760798igc.0!news-out.google.com!j6ni34691qas.0!nntp.google.com!v10no6042522qac.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 10 Aug 2014 13:55:00 -0700 (PDT) In-Reply-To: <19297tmx9dt9q.1p2p4i0odtkyw.dlg@40tude.net> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=213.108.152.51; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S NNTP-Posting-Host: 213.108.152.51 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> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: A bad counterintuitive behaviour of Ada about OO From: Maciej Sobczak Injection-Date: Sun, 10 Aug 2014 20:55:00 +0000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:21645 Date: 2014-08-10T13:55:00-07:00 List-Id: W dniu sobota, 9 sierpnia 2014 18:48:33 UTC+2 u=C5=BCytkownik Dmitry A. Kaz= akov napisa=C5=82: > 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. > Factory pattern in Ada is this: >=20 > type Factory is abstract tagged null record; >=20 > function Make (F : not null access Factory) return A'Class; >=20 > Then you do: >=20 > type A_Factory is new Factory with ... >=20 > override function Make (F : not null access A_Factory) return A'Class; >=20 > type B_Factory is new Factory with ... >=20 > override function Make (F : not null access B_Factory) return A'Class; >=20 > And in case you do know the result type no factory object is ever needed, > because you just do: >=20 > X : A; Wrong. Or rather half-way right. I also want to do this: Y : B :=3D Make (B_F); In other words, if I know that I have a Cat_Shelter, then I want to get a r= eal Cat from it, not some unspecified Animal (nor Animal'Class). So I want = this to be possible: X : A :=3D Make (A_F); -- base obj from base factory Y : B :=3D Make (B_F); -- derived obj from derived fry Z_1 : A'Class :=3D Make (A_F); -- class-wide from base fry Z_2 : A'Class :=3D Make (B_F); -- class-wide from derived fry All of them have real-life interpretations with any of the example use-case= s that I have listed below. I can do all of them in C++. > It cannot work in any language, even if full MD were supported, which wou= ld > make your example possible. The pattern is just useless. Useless? - A Singer can sing a Song, but a Blues_Singer can sing a Blues_Song. - I can get an Animal from an Animal_Shelter, but I can get a Cat from the = Cat_Shelter (this is the Wikipedia example). - A Coffee_Machine can make a Coffee, but a Special_Coffee_Machine can make= a Special_Coffee. - A Programmer can write a Program, but an Ada_Programmer can write an Ada_= Program. - (etc. billion of other such examples) As I have already stated, every creational design patter can benefit from c= ovariance on return type. I would not call this "useless". > > This is *exactly* the definition of covariance, at least the one I know= : >=20 > The notion of co- and contra-variance was given by Luca Cardelli. It is > related strictly to inheritance <=3D> a hierarchy. Outside a hierarchy it= is > just meaningless. You must have failed to read the Wikipedia articles that I have pointed. > >> No OOPL I know can handle this. >=20 > > Have you heard about those niche and unpopular languages like C++ and J= ava? ;-) >=20 > Yes. They cannot handle this either. You must have failed to read the Wikipedia articles that I have pointed. > Usual technique in C++ and Ada is to use template or generic to produce t= he > handle type. Unrelated. Please focus on the examples that I have provided. --=20 Maciej Sobczak * http://www.msobczak.com * http://www.inspirel.com