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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Using interfaces Date: Sat, 2 Jun 2018 19:00:15 +0200 Organization: Aioe.org NNTP Server Message-ID: References: <795d1d54-0868-4745-8132-b38165494f39@googlegroups.com> NNTP-Posting-Host: CvkHMVp693S8Z+lk11jyqg.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 X-Notice: Filtered by postfilter v. 0.8.3 Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:52859 Date: 2018-06-02T19:00:15+02:00 List-Id: On 2018-06-02 17:20, gautier_niouzes@hotmail.com wrote: > I am developing a package for displaying some kinds of figures on an open set of devices. I'm trying to use interfaces for that. This is full multiple dispatch [*]: procedure Draw ( Shape : Figure; Surface : in out Device ) is abstract; -- This is not Ada! Interfaces is no [direct] help. Usually multiple dispatch is replaced with cascaded dispatch. You first dispatch on the figure and then on the device from the implementation of Draw: type Device is limited interface; -- Drawing primitives procedure Draw_Filled_Rectangle ( Surface : in out Device; Box : Rectangle; Color : RGBA_Color ) is abstract; ... type Figure is interface; procedure Draw ( Shape : Figure; Surface : in out Device'Class -- No dispatch ) is abstract; type Filled_Rectangle is new Figure with record Position : Box; Color : RGBA_Color; end record; overriding procedure Draw ( Shape : Filled_Rectangle; Surface : in out Device'Class ); procedure Draw ( Shape : Filled_Rectangle; Surface : in out Device'Class ) is begin Surface.Draw_Filled_Rectangle (Shape.Position, Shape.Color); end Draw; This is too simple to work always in practice. There is no replacement for multiple dispatch. ------------------------------- * A simplified form of multiple dispatch is multi-method when only one types hierarchy is involved, like in arithmetic operations. Full multiple dispatch is when different type hierarchies share operations like Figure and Device share Draw. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de