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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c7c302806c75a91b,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,UTF8 Received: by 10.66.89.164 with SMTP id bp4mr5685942pab.14.1351711713004; Wed, 31 Oct 2012 12:28:33 -0700 (PDT) Path: s9ni72247pbb.0!nntp.google.com!news.glorb.com!aioe.org!.POSTED!not-for-mail From: =?utf-8?Q?Yannick_Duch=C3=AAne_=28Hibou57?= =?utf-8?Q?=29?= Newsgroups: comp.lang.ada Subject: Design by contract and control inversion Date: Wed, 31 Oct 2012 20:28:30 +0100 Organization: Ada @ Home Message-ID: NNTP-Posting-Host: 3v6cAj3XpvZHyQb0RelZrQ.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: Opera Mail/12.02 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: Quoted-Printable Date: 2012-10-31T20:28:30+01:00 List-Id: Hi all, I wondered if there are known idioms to express predicates for callbacks= , = which may be via access to subprogram or interface/tagged types. Control= = inversion seems to not be easily mixable with design by contract. An = example to make it clearer. Say a type `T` has a method with expect either an access to subprogram o= r = an interface: type T is private; procedure Expect_Handler (Me : T; Handler : not null access procedure (Context : T)); type H is interface; procedure Handle (Me : H; Context : T) is abstract; procedure Expect_Handler (Me : T; Handler : H'Class); Now let say the type `T` has different properties, and one is always = `True` when no handler in currently invoked, and always `False` when an = = handler is currently running (which may be nesting), so that from inside= = of any `Handle` interface method of subprogram, then that property will = = always be `False`, and that I want it to be part of the specification. I can't make it a precondition for the `Handle` method of type `H`, that= = would not be clean and not what's really intended. Worst, I can't expres= s = anything at all with the access to subprogram case. The only thing I could imagine, is to create a second type, `U`, = re=E2=80=91interfacing `T`, and passed to the handlers instead of `T`: type T is private; type U (<>) is limited private; procedure Expect_Handler (Me : T; Handler : not null access procedure (Context : U)); type H is interface; procedure Handle (Me : H; Context : U) is abstract; procedure Expect_Handler (Me : T; Handler : H'Class); And in the private part, one of `U` or `T` wraps the other (within a = record). Not that clean, but at least, `T` and `U` can expose different = = properties, and `U` is only used to be passed as parameters to handlers.= = This construct is not only interesting for design by contract, as it als= o = allows to expose a different subprogram set for both type; as an example= , = in the real thing I did, `U` only gets a subset of the subprograms = applicable to `T`. Do you believe that's the best way to do? Or is this too much tricky and= = you know another idiom? -- = =E2=80=9CSyntactic sugar causes cancer of the semi-colons.=E2=80=9D [1] =E2=80=9CStructured Programming supports the law of the excluded muddle.= =E2=80=9D [1] [1]: Epigrams on Programming =E2=80=94 Alan J. =E2=80=94 P. Yale Univers= ity