版权声明:本文首发 http://asing1elife.com ,转载请注明出处。 https://blog.csdn.net/asing1elife/article/details/83384793
某些情况下 应该用继承关系代替调用关系
更多精彩
- 更多技术博客,请移步 asing1elife’s blog
动机
- 两个类之间存在调用关系,但却过于频繁的进行调用
例外
- 尽管调用关系非常频繁,但并没有用到调用类的所有方法,则应该使用 7.6 Remove Middle Man 移除中间人 尽可能减少多余的调用关系
- 或者使用 11.7 Extract Superclass 提炼父类 将两个类相同的部分提炼到父类中