理解:和提升字段正好相反,跟降低方法类似,就是把基类中,只有部分继承类需要用到的字段,降低到继承类自身去。
详解:
重构前代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace _31DaysRefactor
{
public abstract class Task
{
protected string _resolution;
} public class BugTask : Task
{ } public class FeatureTask : Task
{ }
}
重构后代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace _31DaysRefactor
{
public abstract class Task
{
protected string _resolution;
} public class BugTask : Task
{
private string _resolution;
} public class FeatureTask : Task
{ }
}
把 _resolution字段降低到继承类 BugTask中去。