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-Thread: 103376,2ff5c149712ec0eb X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.germany.com!news.belwue.de!th!lucks From: Stefan Lucks Newsgroups: comp.lang.ada Subject: Re: Ada Interfaces and the Liskov Substitution Principle Date: Thu, 24 May 2007 16:41:45 +0200 Organization: InterNetNews at News.BelWue.DE (Stuttgart, Germany) Message-ID: References: <7b9qiwewqptb$.16g096so0lqf8.dlg@40tude.net> NNTP-Posting-Host: th.informatik.uni-mannheim.de Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Trace: news.BelWue.DE 1180017707 449 134.155.91.85 (24 May 2007 14:41:47 GMT) X-Complaints-To: news@news.belwue.de NNTP-Posting-Date: Thu, 24 May 2007 14:41:47 +0000 (UTC) In-Reply-To: <7b9qiwewqptb$.16g096so0lqf8.dlg@40tude.net> Xref: g2news1.google.com comp.lang.ada:15910 Date: 2007-05-24T16:41:45+02:00 List-Id: On Thu, 24 May 2007, Dmitry A. Kazakov wrote: > On Thu, 24 May 2007 13:12:56 +0200, Stefan Lucks wrote: >> You are using a very broad and generalised interpretation of the LSP. My >> interpretation -- and I believe this is the common and usual one -- is >> that "X: in T" in the parameterlist of a subprogram does not deal with >> some "artificial" type "in T", just with "T". > > If it dealt with T, then the following program were legal: > > procedure Foo (X : in out T); > > procedure Bar (X : in T) is > begin > Foo (X): -- Fortunately illegal in Ada > end Bar; The "X: in T" part in Bar's contract means "I (Bar) will abstain from using certain properties X might have" (where "certain properties" are well defined, but I am too lazy to describe them explicitely). When calling "Foo(X)", Bar is trying to break this contract -- and fortunately, the compiler stops that attemtped fraud. Note that ther is a difference between "I will abstain from using" and "I don't provide", and the LSP is all about the second. The fact that inside Bar, the programmer is forced to obey the promise made in the parameter list is not in violation of the LSP. > Yes, but then LSP should be re-formulated appropriately. And there is > nothing automatically wrong in disallowing operations. I would like to see > it in Ada. Is there any language that allows that? I am dreaming of something like type Base is new Some_Tagged_Type with ...; procedure Primitive_1(...); procedure Primitive_2(...); type Super is new Base with out Primitive_2; -- this is not Ada! -- Super "inherits" Primitive_1 from Base, but not Primitive_2. B: Base; S: Super; procedure Class_Wide_Base (Object: Base'Class); procedure Class_Wide_Super(Object: Super'Class); Class_Wide_Base(B); -- legal, of course; Class_Wide_Super(S); -- also legal, of course; Class_Wide_Super(B); -- this should be legal!! Class_Wide_Base(S); -- this should be illegal! This would allow to "take away" operations without actually violating LSP (as I understand LSP). Perhaps the following would in also do the job (of course, I could not define S of type Super, but well ...): type Super is interface Base with out Primitive_2; -- Stefan Lucks (moved to Bauhaus-University Weimar, Germany) ------ I love the taste of Cryptanalysis in the morning! ------