内联类重构
此重构允许您将一个类合并到另一个类中。 被合并的类会被移除,其成员会被移动到使用该类的类中,并且所有对该类的使用都会相应更新。
在下面的示例中,我们将 绘制器 类(即其字段 我的颜色 和其方法 初始化绘制器 )合并到 圆形 类中。
class Painter
{
private Color myColor;
public Painter(Color c)
{
myColor = c;
InitPainter(myColor);
}
private void InitPainter(Color color)
{
//init painter
}
}
class Circle
{
private Painter myPainter;
public Circle(Color c)
{
myPainter = new Painter(c);
}
}
class Circle
{
private Color myColor;
public Circle(Color c)
{
myColor = c;
InitPainter(myColor);
}
private void InitPainter(Color color)
{
//init painter
}
}
内联一个类
应用重构后,属性或字段会被其类型的成员替换。 所有对属性或字段的使用都会相应更新。
2026年 11月 10日