Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
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?
Posted

First of all, look at Apache log4net: http://logging.apache.org/log4net/[^].

I think decoration components with logging is too heavy weight and too much if stiff coupling. I would allow it for an optional feature where logging is often of always useful. In general case, this is no good.

The use of singleton if way more adequate. I would agree that this would be a classic case of singleton usage. "Hard for unit testing?" Hm. I suspect this is just a result of a sick fantasy of some person who does not actually do unit testing. I don't see any specific problems for unit testing here. I can imagine that I'm missing something though. In this case, let this person write to me and explain where is that hardness; I would greatly appreciate it.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900