rename and redefine with an attribute and a method

View: New views
8 Messages — Rating Filter:   Alert me  

rename and redefine with an attribute and a method

by panfriedwoggle :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,

I've been banging my head against this for hours and am now at a loss.

I have:

class A
...
feature
    c: INTEGER
...
end -- A

I want to replace this attribute c in a subclass with a method:

class B

inherit
    A
        rename
            c as c_int -- so all the features that manipulate c in the
superclass still work fine when inherited, and I can get at it too
        redefine
            c -- because I want to redefine it here
        end
...
feature
    my_other_A: A
    c: INTEGER is
        do
            result := c_int + my_other_A.c
        end -- c
end -- B

I cannot get this to work. First, if I included the redefine clause in
B as above it won't compile - fair enough, I have renamed c, so it's
not around for me to redefine. I can just give a new definition for c,
I would think...

... but no. After removing the redefine clause, everything compiles
sweetly, but it does not work. Using the debugger, it seems that
routine c is never entered for objects of class B. It is just
returning the integer that I renamed c_int.

Surely there is a way of overriding an attribute with a method? Isn't
Eiffel supposed to have a Uniform Access Principle?

I am at a loss...

Thanks,

David


------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/


RE: rename and redefine with an attribute and a method

by Emmanuel Stapf [ES] :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> I want to replace this attribute c in a subclass with a method:

The simple answer is that it is not allowed by the language definition. This
is still open to discussion at the ECMA committee but currently the feeling
is that it might make things slower for incremental compiler and will slow
down dynamic access to such entities. However they were not strong feeling
about it. Since this restriction already existed in the past and all
existing compilers have kept this restriction the consensus was to leave
things as they are.

In your case, it means that in your ancestor you have to fake it by hiding
the attribute and exposing a function instead which will be redefined in
descendants.

Hope this helps,
Manu


------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/


Re: rename and redefine with an attribute and a method

by Peter Gummer-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

David wrote:

> ... but no. After removing the redefine clause, everything compiles
> sweetly, but it does not work. Using the debugger, it seems that
> routine c is never entered for objects of class B. It is just
> returning the integer that I renamed c_int.

How are you calling routine c? You need to call it through a variable of
static type B, because routine c does not exist in the ancestor class A.

- Peter Gummer



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/


Re: rename and redefine with an attribute and a method

by Eric Bezault :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Emmanuel Stapf [ES] wrote:
>> I want to replace this attribute c in a subclass with a method:
>
> The simple answer is that it is not allowed by the language definition. This
> is still open to discussion at the ECMA committee but currently the feeling
> is that it might make things slower for incremental compiler and will slow
> down dynamic access to such entities. However they were not strong feeling
> about it. Since this restriction already existed in the past and all
> existing compilers have kept this restriction the consensus was to leave
> things as they are.

Allowing redefinition of attributes to routines also means that
the compiler will have to reject routines inherited from A that
use `c' as the target of an assignment, and hence force the user
to redefine these routines in B.

If ECMA allows this kind of redefinition of attributes to routines,
it will have to be very careful and identify all Eiffel constructs
where the rules and behaviors are different when the entity is an
attribute or a routine, as shown above for assignments.

--
Eric Bezault
mailto:ericb@...
http://www.gobosoft.com

------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/


Re: rename and redefine with an attribute and a method

by Thomas Beale-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Eric Bezault wrote:
 >

 >
 > Allowing redefinition of attributes to routines also means that
 > the compiler will have to reject routines inherited from A that
 > use `c' as the target of an assignment, and hence force the user
 > to redefine these routines in B.
 >
 > If ECMA allows this kind of redefinition of attributes to routines,
 > it will have to be very careful and identify all Eiffel constructs
 > where the rules and behaviors are different when the entity is an
 > attribute or a routine, as shown above for assignments.

On the other hand, not allowing it takes away the choice to convert a
stored representation of something into a computed form, which is one of
the goals of the rule of uniform access (which is still one of the most
powerful and under-recognised bits of genius - even if obvious in
hindsight - in Eiffel).

--
    Thomas Beale
Chief Technology Officer, Ocean Informatics

Chair Architectural Review Board, openEHR Foundation
Honorary Research Fellow, University College London





------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/


Re: rename and redefine with an attribute and a method

by Eric Bezault :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thomas Beale wrote:

> Eric Bezault wrote:
>  >
>
>  >
>  > Allowing redefinition of attributes to routines also means that
>  > the compiler will have to reject routines inherited from A that
>  > use `c' as the target of an assignment, and hence force the user
>  > to redefine these routines in B.
>  >
>  > If ECMA allows this kind of redefinition of attributes to routines,
>  > it will have to be very careful and identify all Eiffel constructs
>  > where the rules and behaviors are different when the entity is an
>  > attribute or a routine, as shown above for assignments.
>
> On the other hand, not allowing it takes away the choice to convert a
> stored representation of something into a computed form, which is one of
> the goals of the rule of uniform access (which is still one of the most
> powerful and under-recognised bits of genius - even if obvious in
> hindsight - in Eiffel).

That's why I was one of the proponent of allowing this kind
of redefinition when it was discussed at ECMA. I just wanted
to point out that we have to be careful if we allow it. It's
not just about relaxing a rule, it has nested implications.

--
Eric Bezault
mailto:ericb@...
http://www.gobosoft.com

------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/


Re: rename and redefine with an attribute and a method

by Colin LeMahieu :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Would forcing them to also define an assigner, as a validity
constraint, be sufficient?

--- In eiffel_software@..., Eric Bezault <ericb@...> wrote:
>
> Emmanuel Stapf [ES] wrote:
> >> I want to replace this attribute c in a subclass with a method:
> >
> > The simple answer is that it is not allowed by the language
definition. This
> > is still open to discussion at the ECMA committee but currently
the feeling
> > is that it might make things slower for incremental compiler and
will slow
> > down dynamic access to such entities. However they were not strong
feeling
> > about it. Since this restriction already existed in the past and all
> > existing compilers have kept this restriction the consensus was to
leave

> > things as they are.
>
> Allowing redefinition of attributes to routines also means that
> the compiler will have to reject routines inherited from A that
> use `c' as the target of an assignment, and hence force the user
> to redefine these routines in B.
>
> If ECMA allows this kind of redefinition of attributes to routines,
> it will have to be very careful and identify all Eiffel constructs
> where the rules and behaviors are different when the entity is an
> attribute or a routine, as shown above for assignments.
>
> --
> Eric Bezault
> mailto:ericb@...
> http://www.gobosoft.com
>



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/


Re: Re: rename and redefine with an attribute and a method

by Eric Bezault :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

colinlema wrote:
> Would forcing them to also define an assigner, as a validity
> constraint, be sufficient?

No, because assigners are for "remote" assignments,
of the form:

   a.b := c

They don't come into play when we have:

   a := b

--
Eric Bezault
mailto:ericb@...
http://www.gobosoft.com

------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/eiffel_software/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:eiffel_software-digest@...
    mailto:eiffel_software-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    eiffel_software-unsubscribe@...

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/