New ActionScript/Flex Refactoring: Push Members Down

In addition to other refactorings, Maia also has this useful refactoring: push members down the classes hierarchy.

Again, let’s try it on a simple example.

Play a bit more with 2D shapes API — assume one has Solid interface that supports fill()-ing and controlling the opacity of solid objects, with implementing class Shape that has two inheritors: Rectangle and Circle.

When introducing class for PolyLine shape, you can realize that not all shapes are solid, i.e. have a content to fill. So, API needs to be changed slightly: solid-related features should be pushed down to the classes where they actually belong. This is where our new refactoring helps: just place caret anywhere inside of Shape class code and invoke Refactor | Push Members Down.

Note: you can move not only class members, but also interfaces from the implements list!

Here you select members to move. As for other similar refactorings, when we select a member that is used by another, the latter is highlighted with red (if not selected). Now, press Refactor and see what happens!

Just as planned, selected members are removed from their original class and pushed down to each of the subclasses.

Note: when pushing method or property of an interface to the class that does not yet implement it, IntelliJ IDEA creates a dummy implementation stub (just as if you used Implement Methods intention). For such member you may select Keep abstract option to prevent IntelliJ IDEA from removing its declaration from that interface. You may also control whether IntelliJ IDEA should move, copy, or keep ASDoc for these members.

Refactor with pleasure!

This entry was posted in New Features and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">