Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

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?

share|improve this question
This isn't really a code review request - it doesn't contain any code. – sepp2k May 10 '12 at 7:42

closed as off topic by Jeff Mercado, sepp2k May 10 '12 at 7:39

Questions on Code Review Stack Exchange are expected to relate to code review request within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

up vote 0 down vote accepted

The best way to do this would be to use an IoC container, and configure it to feed all the LoggingComponentDecorators the same instance of LogService.

This way you have a single LogService instance (the IoC container can manage that for you) and you don't have any unit testing issues.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.