Measuring Cohesion - The LCOM principle
There has been a constant doubt in my mind since I got to know about the pattern of developing applications based on DDD. Still a novice, I quite frequently come across situations where I'm not sure what the best place to put a particular piece of functionality is. I take a calculated risk, quite often a wrong one, trying to assess the after effects. I recently came across this great read on cohesion. What should be a "good enough" basis for deciding how cohesive should different pieces of functionalities be. And I particularly loved the example provided: Considering two different implementations of the same functionality: Class A{ getDevices() createDevice() modifyDevice() removeDevice() repairDevice() diagnoseDevice() } It's quite logical to think of all the methods to be directly related to a device. But upon a closer look, one might say that the last two methods only deal with troubleshooting the device. Should the last two methods then sit inside a TroubleShootDe...