版权声明:本文首发 http://asing1elife.com ,转载请注明出处。 https://blog.csdn.net/asing1elife/article/details/83104357
在调用类中建立一个方法,并以第一参数形式传入一个服务类实例
更多精彩
- 更多技术博客,请移步 asing1elife’s blog
后置条件
- 如果在调用类中引入了过多的方法,则需要考虑使用 7.8 Introduce Local Extension 引入本地扩展
动机
- 服务类现有方法无法满足程序需求,但没有权限直接修改这个服务类
案例
Date newStart = new Date(previousEnd.getYear(), previousEnd.getMonth(), previousEnd.getDate() + 1);
Date newStart = nextDay(previousEnd);
private static Date nextDay(Date date) {
return new Date(date.getYear(), date.getMonth(), date.getDate() + 1);
}