封装重复代码的方法有: 提取方法:在一个类里提取重复部分的code生成方法,在其他使用的地方直接调用。pull up方法:把两个兄弟类中重复的方法,放到父类中实现。提取成类:使用组合的方法。封装成静态的工具类。使用单例。重载类型的方法,参数少的去调用参数多的,在多出的参数里传入默认值。