Sunday, May 29, 2011

Side Effects - part 1

In my last post I mentioned the concept of side effects as one of my "pet peeves".

How othen have you implemented a method/function that does more than logically "task"?
It might have been an update of a persistent entity which also, in same method, added an audit log entry to the audit log. Or perhaps the "create" method of the Order service, also sends an email to the customer.

This is what I call side-effects, an effect of a task which has nothing really to do with the basic task at hand, in the above mentioned examples, update and creation of persistent entities.

Its often quite easy to implement the logic in the same method as the task to which it is closely coupled but I think it is a rather bad design.
In case of the Order service, how to differentiate creation of orders created by customers and e.g. system generated orders? Then you start to add booleans to method, signalling whether or not perform the side-effects and suddently you carry this information around from method to method.

Side-effects has no place in base logic, and its ALL in the context...

Part 2 : Side-effects and transactions

1 Comments:

Blogger Fahad Naseer said...

Which Car you want..? Here is a best list of Cars and Vehicles, Hot Vehicles, Strange Cars, Super Cars Model, Funny Cars, Car Latest Models, Cars with Girls, Cars like helicopter and Most Speed and Expensive Cars
WorldLatestVehicles.com

19/4/13 21:10  

Post a Comment

<< Home