質問

What is a good design pattern to document or log every operation (business logic) that is done inside the system?

Let's say I want to write a small log or notify the user about every operation? For instance, in the system you may order a cleaning service for your house and I want to give the user feedback after each step:

Cleaning service ordered > cleaning is being done > cleaning is finished

I was thinking about Observer pattern but I'm a bit confused. Thanks.

役に立ちましたか?

解決

If you wish to log every time /something/ happens then it's what's called a cross cutting concern. By this I mean something that happens /outside normal operation/ - it happens everywhere. Look at Aspecxt orientated programming (AOP) - logging is a classic AOP problem. http://en.wikipedia.org/wiki/Aspect-oriented_programming for more info.

他のヒント

What you want desire is know as a cross-cutting concern. Take a look at Aspect Oriented programming. You can write code that is executed on method calls, where you select the method call based on semantic java signatures.

This will decouple your logging concern from your business logic concerns. You should find some immediate examples in the AspectJ documentation.

http://eclipse.org/aspectj/doc/released/progguide/starting-development.html#profiling-and-logging

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top