What are the methods to increase grip while maintaining the junction?

Loose connection, high grip for supported application

This is the battle cry that I hear over and over. There are many tips on how to mix components freely.

  • Base on interfaces and injection of all dependencies
  • Use events
  • Use Service Bus
  • and etc.

However, I feel that I have never heard any concrete proposals to increase cohesion. Can anyone suggest?

You can start answering it, but I have such a specific situation that I would also like to consult.


I have a fairly loosely coupled C # Windows Forms MVP application that bundles many of its components from interfaces, injects them through constructors, and uses the Inversion of Control (Castle Windsor) container to put it all together.

I would say it is pretty well archived - it has gone through large change requests several times already and handled them easily. I am generally quite happy with this, but I just cannot shake the dubious doubt that he is not particularly cohesive. This is not a problem for me as a sole developer, but I'm afraid it might get confusing for someone new to the app.

Let me give you an example: An application is used by Company A to populate and process outbound product trucks. This means that there is an OutgoingTransactionInfo object , OutgoingTransactionInfoControl (to actually enter the specified information), OutgoingTransactionValidator, and OutgoingTransactionPersister . >. With the application in production, we received a request to process incoming transactions: they receive different information, a different check and a different way to save them. Then Company B also wanted to use a transaction processing application, the idea is similar, but again, information, checks, persistence, and maybe a few other components are different.

Since my application has a good test suite and is free, I was able to satisfy these requests easily. However, I understand that it is all too easy to accidentally set it up in an invalid state. For example, you can wire it up to use OutgoingTransactionInfo objects when validating with IncomingTransactionValidator . If the differences are minor, the error may even disappear over time.

Do you have any suggestions for me? What methods do you use to mitigate this risk?

+2


source to share


4 answers


Cohesion means you don't put unrelated things together in a module (class, ...). From your description, you seem to be doing it beautifully. Proper testing (which you think should be done too) should keep risks under control.

You can probably use the type system (generics / templates) to make sure the information and its validator fit together and maybe keep some code / make it more uniform (make sure the added complexity is worth it).



Otherwise, keep doing good work.

+3


source


You achieve a very cohesive system where each component of the system is focused on one responsibility. As the saying goes, "Do one thing and do it well." When you feel like a class is starting to be "too much," you can refactor it into two or more classes, each responsible for one thing. This leads to a weakening of the connection: since each of these functions is localized in a specific class, the classes most likely have very discrete interactions with each other.



A quick suggestion for your connection problem: Couldn't your OutgoingAbc class be checked so that it would receive OutgoingXyz when connected together and throw an exception if it was wrong?

+1


source


One thing that comes to mind is visibility control. (I'll speak in Java, but I think these concepts translate into other languages). What can OutgoingTransactionValidator "see" ? Is it okay for it to be visible outside of the my.org.outgoing package ?

This way, the miss can be controlled without making it public.

By adopting this concept in the OSGi phase, you can explicitly declare which packages a package exports and which packages a package uses, so dependencies become much more explicit and controllable.

+1


source


Here's an interesting presentation by Jim Weirich on pairing and cohesion from a Ruby perspective from the 2009 Mountain Mountain Ruby conference, Deals with varying degrees and when they may or may not be appropriate.

+1


source







All Articles