World Library  
Flag as Inappropriate
Email this Article

Pull Up refactoring

Article Id: WHEBN0002401323
Reproduction Date:

Title: Pull Up refactoring  
Author: World Heritage Encyclopedia
Language: English
Subject: Code refactoring, Pull up, Push Down
Collection: Code Refactoring
Publisher: World Heritage Encyclopedia
Publication
Date:
 

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.

Application

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 less code duplication and better code readability. This refactoring should not 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 its 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
     }
 }

See also

Push Down

This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and USA.gov, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for USA.gov and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
 
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
 
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.
 


Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.