Pull Up refactoring

Pull Up refactoring

In software engineering, Pull Up refactoring involves moving a member of a class, such as a method, from a Subclass into a Superclass.

How and when can this refactoring be applied?

This refactoring is especially useful when subclasses of a certain class share some functionality but each implements it separately. Moving the shared functionality (using Extract Method if need be, or just moving the method) to the superclass will keep the functionality of the subclasses as it is, and give us less code duplication and better code readability.Please note that this refactoring shouldn't be used if only relatively few subclasses share a functionality, since this will add (probably) unintended functionality to other (most of the other ) subclasses. Suppose we have a class A and it's subclasses B, C, D, E, F and G. If B and C share a method (for example), then a better solution in this case is creating a class that will have the B and C's shared method (let's call it Z), and have B and C use the method from that class (Z in this example). That process is called Extract Class.Another option would be making Z extend A and then making B and C extend Z.

Examples

Compare the following Java classes before and after the Pull Up refactoring is applied on myMethod2:

public class Superclass{ void myMethod(){ //do something } } public class Subclass extends Superclass{ void myMethod() { //do something } void myMethod2() { //do something else } }

After the Pull Up refactoring is applied: public class Superclass{ void myMethod(){ //do something } void myMethod2() { //do something else } } public class Subclass extends Superclass{ void myMethod() { //do something } }

ee also

Push Down


Wikimedia Foundation. 2010.

Игры ⚽ Нужен реферат?

Look at other dictionaries:

  • Pull up — can mean:* Pull up (exercise), an upper body compound pull exercise * Pull up resistor, a technique in digital electronics * Pull up transistor, a transistor used in analog electronics * Pull Up refactoring, a technique used in object oriented… …   Wikipedia

  • Code refactoring — Refactor redirects here. For the use of refactor on Wikipedia, see Wikipedia:Refactoring talk pages. Code refactoring is disciplined technique for restructuring an existing body of code, altering its internal structure without changing its… …   Wikipedia

  • Push Down — In software engineering, Push Down refactoring involves moving a method from a superclass into a subclass. Compare the following Java classes before and after the Push Down refactor is applied: public class SuperClass{ void methodA() { //do… …   Wikipedia

  • NetBeans — IDE NetBeans IDE 6.0 Basisdaten Entwickler: Sun Microsystems Aktuelle Version …   Deutsch Wikipedia

  • NetBeans IDE — Dieser Artikel wurde aufgrund von inhaltlichen Mängeln auf der Qualitätssicherungsseite der Redaktion Informatik eingetragen. Dies geschieht, um die Qualität der Artikel aus dem Themengebiet Informatik auf ein akzeptables Niveau zu bringen. Hilf… …   Deutsch Wikipedia

  • Netbeans — IDE NetBeans IDE 6.0 Basisdaten Entwickler: Sun Microsystems Aktuelle Version …   Deutsch Wikipedia

  • Refactorisation — Synonymes de « Refactorisation » : Réusinage (au Québec). La refactorisation (anglicisme venant de refactoring) est une opération de maintenance du code informatique. Elle consiste à retravailler le code source non pas pour… …   Wikipédia en Français

  • Рефакторинг — (англ. refactoring) или реорганизация кода   процесс изменения внутренней структуры программы, не затрагивающий её внешнего поведения и имеющий целью облегчить понимание её работы[1][2]. В основе рефакторинга лежит последовательность… …   Википедия

  • Lean software development — is a translation of lean manufacturing principles and practices to the software development domain. Adapted from the Toyota Production System, a pro lean subculture is emerging from within the Agile community. Origin The term Lean Software… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”