comp.lang.ada
 help / color / mirror / Atom feed
* Q: Refactorizing code because Inheritance and Interfaces
@ 2003-10-18  9:10 Michael Erdmann
  2003-10-20 18:57 ` Stephen Leake
  2003-10-21  5:48 ` Simon Wright
  0 siblings, 2 replies; 10+ messages in thread
From: Michael Erdmann @ 2003-10-18  9:10 UTC (permalink / raw)


Dear all,

again i got a problem with inheritance. Lets assume the following
situation, that you have made a nice package reading in xml
files. The specification contains something like this:

    package XML_Reader is .
       type Object is new Sax.... with ... bla...
       procedure X(This : in out Object......)

Some weeks later i have realized that this implemenation is nice, 
but it is part of a generalization:

    package Abtract_Reader is
        type Object is abstract tagged null record;
        type Handle is access all Object'Class;

        procedure X(.... ) is abstract;

In order to line up the implemenation of the XML_Reader with the 
Abstract_Reader interface i need to rewrite the complete XML_Reader.
Is there any way to avoid such situations?


Regards
    M.Erdmann


PS:
In java i would use   constructs as implements  Sax..,Abstract_Reader.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Q: Refactorizing code because Inheritance and Interfaces
  2003-10-18  9:10 Q: Refactorizing code because Inheritance and Interfaces Michael Erdmann
@ 2003-10-20 18:57 ` Stephen Leake
  2003-10-21 19:58   ` Michael Erdmann
  2003-10-21  5:48 ` Simon Wright
  1 sibling, 1 reply; 10+ messages in thread
From: Stephen Leake @ 2003-10-20 18:57 UTC (permalink / raw)


Michael Erdmann <Michael.Erdmann@snafu.de> writes:

> In order to line up the implemenation of the XML_Reader with the 
> Abstract_Reader interface i need to rewrite the complete XML_Reader.
> Is there any way to avoid such situations?

In general, no. Refactoring is hard work. That's why it's worth doing :).

> In java i would use   constructs as implements  Sax..,Abstract_Reader.

Ada 200Y will have interface inheritance similar to Java's. But you
still need to rewrite the implementation, so I don't see that as
saving much work.

You can get something similar to interface inheritance in Ada 95 using
generic mixins. It depends on the details of what you are doing
exactly what approach to take.

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Q: Refactorizing code because Inheritance and Interfaces
  2003-10-18  9:10 Q: Refactorizing code because Inheritance and Interfaces Michael Erdmann
  2003-10-20 18:57 ` Stephen Leake
@ 2003-10-21  5:48 ` Simon Wright
  2003-10-21  8:38   ` Marius Amado Alves
  2003-10-21 20:01   ` Michael Erdmann
  1 sibling, 2 replies; 10+ messages in thread
From: Simon Wright @ 2003-10-21  5:48 UTC (permalink / raw)


Michael Erdmann <Michael.Erdmann@snafu.de> writes:

> In order to line up the implemenation of the XML_Reader with the
> Abstract_Reader interface i need to rewrite the complete XML_Reader.
> Is there any way to avoid such situations?

Not sure it's what you had in mind, but J-P. Rosen's web site
(Adalog) has an application (adasubst) that performs renamings etc
over a whole program .. http://perso.wanadoo.fr/adalog/adalog2.htm,
follow the "Ada resources" link.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Q: Refactorizing code because Inheritance and Interfaces
  2003-10-21  5:48 ` Simon Wright
@ 2003-10-21  8:38   ` Marius Amado Alves
  2003-10-21 19:50     ` Michael Erdmann
  2003-10-21 20:01   ` Michael Erdmann
  1 sibling, 1 reply; 10+ messages in thread
From: Marius Amado Alves @ 2003-10-21  8:38 UTC (permalink / raw)
  To: comp.lang.ada

Michael Erdmann <Michael.Erdmann@snafu.de> writes:
> In order to line up the implemenation of the XML_Reader with the
> Abstract_Reader interface i need to rewrite the complete XML_Reader.
> Is there any way to avoid such situations?

Yes. Formal packages. I'm planning a tutorial on this. Also takes care
of interfaces.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: Q: Refactorizing code because Inheritance and Interfaces
@ 2003-10-21  9:00 Lionel.DRAGHI
  0 siblings, 0 replies; 10+ messages in thread
From: Lionel.DRAGHI @ 2003-10-21  9:00 UTC (permalink / raw)
  To: comp.lang.ada

| -----Message d'origine-----
| De: Stephen Leake [mailto:Stephe.Leake@nasa.gov]
...
| > In order to line up the implemenation of the XML_Reader with the 
| > Abstract_Reader interface i need to rewrite the complete XML_Reader.
| > Is there any way to avoid such situations?
| 
| In general, no. Refactoring is hard work. That's why it's 
| worth doing :).

Some times ago, someone posted on cla a request for comments on refactoring
practice. It was aimed at defining some Ada refactoring tools.

Someone knows about this?

-- 
Lionel Draghi  



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Q: Refactorizing code because Inheritance and Interfaces
  2003-10-21  8:38   ` Marius Amado Alves
@ 2003-10-21 19:50     ` Michael Erdmann
  2003-10-25 12:11       ` Georg Bauhaus
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Erdmann @ 2003-10-21 19:50 UTC (permalink / raw)


Marius Amado Alves wrote:

> Michael Erdmann <Michael.Erdmann@snafu.de> writes:
>> In order to line up the implemenation of the XML_Reader with the
>> Abstract_Reader interface i need to rewrite the complete XML_Reader.
>> Is there any way to avoid such situations?
> 
> Yes. Formal packages. I'm planning a tutorial on this. Also takes care
> of interfaces.

What are formal packages? Do you mean generics in some sense?

Michael




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Q: Refactorizing code because Inheritance and Interfaces
  2003-10-20 18:57 ` Stephen Leake
@ 2003-10-21 19:58   ` Michael Erdmann
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Erdmann @ 2003-10-21 19:58 UTC (permalink / raw)


Stephen Leake wrote:

> Michael Erdmann <Michael.Erdmann@snafu.de> writes:
> 
>> In order to line up the implemenation of the XML_Reader with the
>> Abstract_Reader interface i need to rewrite the complete XML_Reader.
>> Is there any way to avoid such situations?
> 
> In general, no. Refactoring is hard work. That's why it's worth doing :).

Well the code i got a result is not realy nice. The result is now:

1. I had to move the type declaration of the XML Reader into the 
   package body.

2. I needed to define my new type as an implementation of the interface
   is wanted to introdcue.

it looks now like this:

   package ... is

      type Object is new  XX.Interface.Object with private;


   private 
      type Object_Data_Type;

      type Object is new XX.Interface.Object with record
             Data : Object_Data_Access := Initialize;
          end record;

   package


   package body is
  
     type XML_Reader_Type is new SAX ...... with..

     procedure Element_Begin( S : in XML_Reader ....)

     type Object_Type is record
        ....
           Reader : XML_Reader_Type ;
        end record;

   end ..;

This was a lot more refactorizing then i expected! I am now afraid
that i have to spend the effort again, again ......


> 
>> In java i would use   constructs as implements  Sax..,Abstract_Reader.
> 
> Ada 200Y will have interface inheritance similar to Java's. But you
> still need to rewrite the implementation, so I don't see that as
> saving much work.
> 
> You can get something similar to interface inheritance in Ada 95 using
> generic mixins. It depends on the details of what you are doing
> exactly what approach to take.
> 




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Q: Refactorizing code because Inheritance and Interfaces
  2003-10-21  5:48 ` Simon Wright
  2003-10-21  8:38   ` Marius Amado Alves
@ 2003-10-21 20:01   ` Michael Erdmann
  2003-10-23 14:02     ` Jean-Pierre Rosen
  1 sibling, 1 reply; 10+ messages in thread
From: Michael Erdmann @ 2003-10-21 20:01 UTC (permalink / raw)


Simon Wright wrote:

> Michael Erdmann <Michael.Erdmann@snafu.de> writes:
> 
>> In order to line up the implemenation of the XML_Reader with the
>> Abstract_Reader interface i need to rewrite the complete XML_Reader.
>> Is there any way to avoid such situations?
> 
> Not sure it's what you had in mind, but J-P. Rosen's web site
> (Adalog) has an application (adasubst) that performs renamings etc
> over a whole program .. http://perso.wanadoo.fr/adalog/adalog2.htm,
> follow the "Ada resources" link.

Not realy, but i checked it out. If some of the functionality 
would be part of an editor (eg. GPS) is would be a big help.

Michael




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Q: Refactorizing code because Inheritance and Interfaces
  2003-10-21 20:01   ` Michael Erdmann
@ 2003-10-23 14:02     ` Jean-Pierre Rosen
  0 siblings, 0 replies; 10+ messages in thread
From: Jean-Pierre Rosen @ 2003-10-23 14:02 UTC (permalink / raw)


> Michael Erdmann <Michael.Erdmann@snafu.de> writes:
> Not sure it's what you had in mind, but J-P. Rosen's web site
> (Adalog) has an application (adasubst) that performs renamings etc
> over a whole program .. http://perso.wanadoo.fr/adalog/adalog2.htm,
> follow the "Ada resources" link.
>
Thanks for the plug, but *please* use http://www.adalog.fr/adalog2.htm.

The other link (still) works, but might disappear any time.

BTW, anybody with web pages refering to the old links
http://perso.wanadoo.fr/adalog/* or http://pro.wanadoo.fr/adalog/*,
please change them to http://www.adalog.fr/*

-- 
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Q: Refactorizing code because Inheritance and Interfaces
  2003-10-21 19:50     ` Michael Erdmann
@ 2003-10-25 12:11       ` Georg Bauhaus
  0 siblings, 0 replies; 10+ messages in thread
From: Georg Bauhaus @ 2003-10-25 12:11 UTC (permalink / raw)


Michael Erdmann <Michael.Erdmann@snafu.de> wrote:
: Marius Amado Alves wrote:
: 
:> Michael Erdmann <Michael.Erdmann@snafu.de> writes:
:>> In order to line up the implemenation of the XML_Reader with the
:>> Abstract_Reader interface i need to rewrite the complete XML_Reader.
:>> Is there any way to avoid such situations?
:> 
:> Yes. Formal packages. I'm planning a tutorial on this. Also takes care
:> of interfaces.
: 
: What are formal packages? Do you mean generics in some sense?
 
Probably RM
12.7 Formal Packages




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2003-10-25 12:11 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-18  9:10 Q: Refactorizing code because Inheritance and Interfaces Michael Erdmann
2003-10-20 18:57 ` Stephen Leake
2003-10-21 19:58   ` Michael Erdmann
2003-10-21  5:48 ` Simon Wright
2003-10-21  8:38   ` Marius Amado Alves
2003-10-21 19:50     ` Michael Erdmann
2003-10-25 12:11       ` Georg Bauhaus
2003-10-21 20:01   ` Michael Erdmann
2003-10-23 14:02     ` Jean-Pierre Rosen
  -- strict thread matches above, loose matches on Subject: below --
2003-10-21  9:00 Lionel.DRAGHI

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox