From: Logan Capaldo Date: 2006-02-17T07:48:12+09:00 Subject: Re: OT: Is this worth a try? On Feb 16, 2006, at 3:36 PM, Jim Weirich wrote: > Logan Capaldo wrote: >> class C < A >> def meth(n) >> precondition: n > 2 #Will not compile, C#meth accepts a narrower >> range of inputs than A, does not follow Liskov Substitution Principle >> end >> end > > Actually, in Eiffel, this wouldn't be a compile error. > Preconditions in > a derived class is logically ORed with the those in the parent class. > So that the full precondition for C#meth will be > > precondition: (n > 2) || (n > 1) > > Since the preconditions are ORed, they can only be widened in derivied > classes. If you were using full Eiffel syntax, you would state > derived > class preconditions with "require else" rather than the plain > "require" > to help you remember that you can only widen the preconditions. > > Likewise postconditions in derived classes are ANDed with those in > parent classes, so they can only be narrowed (and "ensure and" is used > rather than the vanilla "ensure" [1]). > > -- > -- Jim Weirich > > [1] Ensure in the Eiffel sense (defining preconditions) rather than > ensure in the Ruby sense (finally blocks). > > -- > Posted via http://www.ruby-forum.com/. > See if I ever try to clarify what someone else said ever again. I get twenty closet Eiffel freaks attacking my pseudo-Ruby ;) (I'm kidding...)