Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Refactoring] pushing instance variable up

2 views
Skip to first unread message

Günther Schmidt

unread,
Dec 3, 2005, 2:40:48 PM12/3/05
to
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

Ian Bartholomew

unread,
Dec 3, 2005, 3:03:47 PM12/3/05
to
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.

Günther Schmidt

unread,
Dec 3, 2005, 5:59:04 PM12/3/05
to
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

Ian Bartholomew

unread,
Dec 3, 2005, 6:57:48 PM12/3/05
to
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 Bartholomew

unread,
Dec 4, 2005, 4:35:05 AM12/4/05
to
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.

Chris Uppal

unread,
Dec 4, 2005, 8:48:14 AM12/4/05
to
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


Ian Bartholomew

unread,
Dec 4, 2005, 10:12:40 AM12/4/05
to
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....

John Brant

unread,
Dec 4, 2005, 11:14:26 AM12/4/05
to
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

0 new messages