Refactoring Day 6 : Push Down Field

Opposite of the Pull Up Field refactoring is push down field. Again, this is a pretty straight forward refactoring without much description needed

   1: public abstract class Task
   2: {
   3:     protected string _resolution;
   4: }
   5:  
   6: public class BugTask : Task
   7: {
   8: }
   9:  
  10: public class FeatureTask : Task
  11: {
  12: }

In this example, we have a string field that is only used by one derived class, and thus can be pushed down as no other classes are using it. It’s important to do this refactoring at the moment the base field is no longer used by other derived classes. The longer it sits the more prone it is for someone to simply not touch the field and leave it be.

   1: public abstract class Task
   2: {
   3: }
   4:  
   5: public class BugTask : Task
   6: {
   7:     private string _resolution;
   8: }
   9:  
  10: public class FeatureTask : Task
  11: {
  12: }

 

This is part of the 31 Days of Refactoring series. For a full list of Refactorings please see the original introductory post.

Related Articles:

Post Footer automatically generated by Add Post Footer Plugin for wordpress.

About Sean Chambers

I am a Senior software developer from Palm Coast, Florida. An advocate of Domain Driven Design, Behavior Driven Development, creator of FluentMigrator and community activist. I am married to my beautiful wife Erin and am the proud father of two wonderful children. I currently reside at ACI, a local insurance industry/mortgage software company that excels in creating solutions using Agile methodologies.
This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • Simon

    Isn’t there some copyright being infringed here? Or at least plagiarism. Where is the value add?

  • http://www.lostechies.com/members/schambers/default.aspx schambers

    There isn’t any plagiarism occuring because as you can see from the link at the bottom of the article that points to: http://www.lostechies.com/blogs/sean_chambers/archive/2009/08/01/31-days-of-refactoring.aspx; I give credit to Martin Fowler and other sources of where these refactorings come from. This one was clearly outlined by Fowler in his Refactoring book.

    Furthermore, I don’t see how you could have a “value add” to something as simple as Pushing a field down into a subclass. I suppose I have more wording compared to the original published refactoring by Fowler which only contains a class diagram.

    Just for clarification and completeness if you don’t want to follow the link to the original article which gives credit to Fowler here is the original refactoring published by Martin Fowler: http://www.refactoring.com/catalog/pushDownField.html

    I don’t take lightly to being accused of plagiarism. I am NOT claiming ownership over any of these refactorings, nor did I ever state that they are my idea.