Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

A class that performs both computations and data logging seems to have at least two responsibilities. Given a system for which the specifications require heavy data logging, what kind of design patterns or architectural patterns can be used to avoid bloating all the classes with logging calls every time they compute something?

The decorator pattern be used (e.g. Interpolator decorated to LoggingInterpolator), but it seems that would result in a situation hardly more desirable in which almost every major class would need to be decorated with logging.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

My first thought is to treat the computational parts as a model, and the logging parts as a view. You could then manage the work flow activities of each using a controller or presenter pattern. Substitute other fancy names for each part if you wish, but I see three parts.

So, the controller would initiate the computation, retrieve the result, and relay that to the logger. The computation and logging parts stay ignorant of each other, and the high level logic of your main job is expressed in one place.

share|improve this answer
    
I'm going to go ahead and accept this answer, though I would also appreciate further answers. –  Kazark Dec 24 '12 at 16:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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