[Refactoring] pushing instance variable up

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[Refactoring] pushing instance variable up

Günther Schmidt
Hi,

is there a way to push instance variables up?

Drag and Drop works fine for methods, but if it also works for instance variables I sure haven't found out how yet.

Günther


Reply | Threaded
Open this post in threaded view
|

Re: [Refactoring] pushing instance variable up

Ian Bartholomew-21
Günther,

> is there a way to push instance variables up?
>
> Drag and Drop works fine for methods, but if it also works for instance
> variables I sure haven't found out how yet.

The Class refactoring menu allows you to Push Down and Pull Up instance
variables.  Is that what you mean?

--
Ian

Use the Reply-To address to contact me.
Mail sent to the From address is ignored.


Reply | Threaded
Open this post in threaded view
|

Re: [Refactoring] pushing instance variable up

Günther Schmidt
Ian,

I can see a "Push down" option, but not a "Push up" option anywhere.



Ian Bartholomew wrote:

> Günther,
>
>> is there a way to push instance variables up?
>>
>> Drag and Drop works fine for methods, but if it also works for
>> instance variables I sure haven't found out how yet.
>
>
> The Class refactoring menu allows you to Push Down and Pull Up instance
> variables.  Is that what you mean?
>

Which view is that?

Thanks

Günther


Reply | Threaded
Open this post in threaded view
|

Re: [Refactoring] pushing instance variable up

Ian Bartholomew-21
Günther,

> I can see a "Push down" option, but not a "Push up" option anywhere.

There isn't a "Push Up" but there is a "Pull Up" - the effect is the same.

The difference is that you must be in the superclass to "Pull Up" an
instVar from it's immediate subclass(es).  You can't "Push Up" an inst
var to it's superclass.

FWIW, "Push Down" doesn't seem to be working correctly?.  I'll have a
proper look tomorrow.

I don't know why you can "Push Up" and "Push Down" methods but have to
"Push Down" and "Pull Up" instVars.  There's probably a reason.

> Which view is that?

I was looking in the Class and System Browsers, in the Class menu under
Refactoring.

--
Ian

Use the Reply-To address to contact me.
Mail sent to the From address is ignored.


Reply | Threaded
Open this post in threaded view
|

Re: [Refactoring] pushing instance variable up

Ian Bartholomew-21
I wrote:

> FWIW, "Push Down" doesn't seem to be working correctly?.  I'll have a
> proper look tomorrow.

Nope, it's not broken, just more intelligent than I thought.

> I don't know why you can "Push Up" and "Push Down" methods but have to
> "Push Down" and "Pull Up" instVars.  There's probably a reason.

It does make more sense I suppose.  As more than one subclass could have
an instVar of the same name the concept of "Pulling" all the instVars up
to one place, rather than "Pushing" each one up individually, is closer
to what happens.

--
Ian

Use the Reply-To address to contact me.
Mail sent to the From address is ignored.


Reply | Threaded
Open this post in threaded view
|

Re: [Refactoring] pushing instance variable up

Chris Uppal-3
Ian,

> It does make more sense I suppose.  As more than one subclass could have
> an instVar of the same name the concept of "Pulling" all the instVars up
> to one place, rather than "Pushing" each one up individually, is closer
> to what happens.

Same argument could be applied to methods ;-)

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: [Refactoring] pushing instance variable up

Ian Bartholomew-21
Chris,

> Same argument could be applied to methods ;-)

And I'd just got rid of the headache I'd caused by thinking about this ;_)

I persuaded myself it was different.  Say you have a hierarchy (UPPER =
classes, lower = methods)

AAA
        BBB - zzz
        CCC - zzz

and the implementations of the two zzz are different.  You need to be
able to PushUp an individual method, say BBB>>zzz and leave CCC>>zzz
where it is.  You could implement it as a PullUp to AAA but you would
need the extra step of specifying which zzz to move.

If zzz is an instVar though you can't PushUp one without also PushingUp
the other.  In that case it seems to more sense to turn it around and
make the refactoring a PullUp to AAA.

I think....

--
Ian

Use the Reply-To address to contact me.
Mail sent to the From address is ignored.


Reply | Threaded
Open this post in threaded view
|

Re: [Refactoring] pushing instance variable up

John Brant
In reply to this post by Ian Bartholomew-21
Ian Bartholomew wrote:

> FWIW, "Push Down" doesn't seem to be working correctly?.  I'll have a
> proper look tomorrow.
>
> I don't know why you can "Push Up" and "Push Down" methods but have to
> "Push Down" and "Pull Up" instVars.  There's probably a reason.

The most likely reason is that Don or I named it that way 12 or so years
ago. Originally, all of the refactoring were implemented outside the
browsers in a separate tool (The Refactory). In this tool, you'd select
the refactoring you wanted to perform first, and then select the item
you were refactoring. Given this scenario, it made sense for pull up
variable.

Furthermore, if you study refactoring, you'll noticed that pull up
variable and push down variable are more primitive refactorings that you
can use to implement add variable and remove variable refactorings.
Essentially, you are pulling a new variable up from the nothingness and
pushing a variable into the nothingness. You can't implement pull up or
push down refactorings with add and remove variable refactorings
(although add/remove variable actions are used to implement the pull
up/push down variable refactorings).

Later we integrated the refactorings into a browser. After using the
browser, we decided it would be good to also have push up variable. Most
of the time we wanted to pull a variable up, we were viewing the
variable. It didn't make much sense to have to go to the superclass and
then pull up the variable.

When Martin wrote the refactoring book, we had both pull up and push up
variable menu options. I'm not sure why he chose pull up over push up.
Now, we have Eclipse which calls it "Pull Up...", but you have to be in
a subclass that you are pushing up from.


John Brant