7.7 introduce foreign method(引入外加函数)
来源:互联网 发布:mac rvm 安装ruby 慢 编辑:程序博客网 时间:2024/05/01 16:30
需要为提供服务的类增加一个函数,但你无法修改这个类。
动机:
添加外加函数实现无法修改服务类的新功能。
做法:
在客户类中建立一个函数,用来提供你需要的功能。
=》这个函数不应该调用客户类的任何特性。如果它需要一个值,把该值当作参数传给它。
以服务类实例作为该函数的第一个参数。
旧代码
Date newStart = new Date(previousend.getYear(), previousEnd.getMonth(), previousend.getDate() + 1);
新代码
Date newStart = nextDay(previousEnd);private static Date nextDay(Date arg){ return new Date(arg.getYear(), arg.getMonth(), arg.getDate() + 1);}
- 7.7 introduce foreign method(引入外加函数)
- Introduce Foreign Method(引入外加函数)
- 在对象之间搬移特性之七 :Introduce Foreign Method(引入外加函数)
- 重构笔记——引入外加函数
- 重新组织函数--Introduce Explaining Variable(引入解释性变量)
- 重新组织你的函数之五 :Introduce Explaining Variable(引入解释性变量)
- 简化函数调用之九 :Introduce Parameter Object(引入参数对象)
- Introduce Explaining Variable(引入解释性变量)
- Introduce Local Extension(引入本地扩展)
- Introduce Null Object(引入Null对象)
- 9.7 introduce Null object (引入null对象)
- 7.8 Introduce local extension (引入本地扩展)
- 6.5 Introduce Explaining Variable(引入解释性变量)
- Introduce Parameter Object(引入参数对象)
- introduce
- Introduce
- introduce
- 简化条件表达式之八 :Introduce Assertion(引入断言)
- MFC构架中文档数据的读取和显示(未完)
- strcpy(),strncpy()
- Win7下如何访问Local Settings等拒绝访问的文件夹?
- STL
- web中文乱码问题
- 7.7 introduce foreign method(引入外加函数)
- VC下的小工具
- 文件上传与参数乱码
- C++ STL学习之list
- vs.net环境下的C++编程
- Win32 API编程
- 多线程编程
- 文件下载总结
- linux下用RAW socket发送syn包