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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,dbbbb21ed7f581b X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!bnewspeer01.bru.ops.eu.uu.net!bnewspeer00.bru.ops.eu.uu.net!emea.uu.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Operation can be dispatching in only one type Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <025105f2-5571-400e-a66f-ef1c3dc9ef32@g27g2000yqn.googlegroups.com> <1fgkluza4covm.5lfcsusar8cy$.dlg@40tude.net> <808f80de-bf2d-4546-b39a-2fb3979449c2@k19g2000yqc.googlegroups.com> Date: Fri, 13 Nov 2009 22:14:09 +0100 Message-ID: NNTP-Posting-Date: 13 Nov 2009 22:14:10 CET NNTP-Posting-Host: 5fb4a3a9.newsspool3.arcor-online.net X-Trace: DXC=4Qbn1GV4PW[U6b:FjPaGjQMcF=Q^Z^V3X4Fo<]lROoRQ8kF On Fri, 13 Nov 2009 12:43:42 -0800 (PST), xorque wrote: > The only real requirement is that: > > Archivers use a common protocol: Code just sees operations > on Archiver_t'Class and doesn't know if it's reading from a Zip, RAR, > directory, etc. > > Presumably, then, when I open a file using an operation from an > archiver, I can't know about the implementation of the actual file > as it's private to the archiver. > > Hence, I've ended up with two private tagged types. Is there a better > way (I've not ignored your other suggestions, I'm just exploring other > possibilities first)? MD is customary replaced my mix-in: 1. Standard mix-in: type File_Type is abstract new Ada.Finalization.Limited_Controlled with null record; procedure Open ( File : in out File_Type; Path : String ) is abstract; procedure Close (File : in out File_Type) is abstract; procedure Read ...; procedure Write ...; Files know nothing about archives. Archive has a file as a mixin: type Archiver_Type (Transport : not null access File_Type'Class) is new Ada.Finalization.Limited_Controlled with null record; procedure Open (Archiver : in out Archiver_Type; Path : String); Open of Archive_Type calls to Open of Archive.Transport. Same with other operations. They all are defined in terms of the operations of File_Type. Class through Archive.Transport are dispatching, because it is class-wide. 2. Generic mix-in. You can put Archive in the hierarchy of File_Type. The implementation of Archive_Type can be generic taking a descendant of File_Type and then extending it in the generic body. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de