Los Techies : Blogs about software and anything tech!

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.

Kick It on DotNetKicks.com
Posted Aug 06 2009, 08:20 AM by schambers

Comments

Simon wrote re: Refactoring Day 6 : Push Down Field
on 08-06-2009 6:03 PM

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

schambers wrote re: Refactoring Day 6 : Push Down Field
on 08-06-2009 7:21 PM

There isn't any plagiarism occuring because as you can see from the link at the bottom of the article that points to: www.lostechies.com/.../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: www.refactoring.com/.../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.

张荣华 wrote 31天重构指南之六:降低字段
on 09-28-2009 1:53 AM

与提升方法相似,提升字段也有一个相反的重构叫“降低字段”,降低字段是一个简单到不需要我们多说的重构,来看下面的代码:

31 Days of Refactoring « Vincent Leung's .NET Tech Clips wrote 31 Days of Refactoring « Vincent Leung's .NET Tech Clips
on 10-28-2009 9:28 AM

Pingback from  31 Days of Refactoring « Vincent Leung's .NET Tech Clips

PetterLiu wrote 31 Days of Refactoring
on 11-27-2009 4:01 AM

Refactoring Day 1 : Encapsulate Collection Refactoring Day 2 : Move Method Refactoring Day 3 : Pull ...

PetterLiu wrote 31 Days of Refactoring
on 11-27-2009 4:02 AM

Refactoring Day 1 : Encapsulate Collection Refactoring Day 2 : Move Method Refactoring Day 3 : Pull ...

Add a Comment

(required)  
(optional)
(required)  
Remember Me?

Enter the numbers above:
Copyright Los Techies 2008, 2009. All rights reserved.
Powered by Community Server (Commercial Edition), by Telligent Systems