本文介绍了将LogService添加到我的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个应用程序(旧版代码)
包含带有`save()`方法的接口`Icomponent`
和许多实现它的类.
我想在每个save()之后添加日志.
我以为
将装饰器模式与其他`log()`方法一起用于`Icomponent`.
创建从每个装饰器的log()中调用的LogService类.
我认为LogService是singelton的经典案例,但我读过它很难进行单元测试.
I have an application (Legacy code)
that contains interface `Icomponent` with `save()` methods
and many classes that implement it.
I want to add log after every save().
I thought to
use the decorator pattern to `Icomponent` with additional `log()` method.
create `LogService` class which is called from each decorator''s `log()`
I think `LogService` is a classic case of singelton, but I read it would be hard for unit-testing.
What would be you design to that solution?
推荐答案
这篇关于将LogService添加到我的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!