Search code examples
springcouplingtightly-coupled-code

Implementing an interface is tight coupling?


It says here that

I would not recommend to use InitializingBean and DisposableBean interface, because it will tight coupled your code to Spring

Does it make sense? I thought this would be just the opposite to tight-coupling.


Solution

  • Here the author means that if you let your application classes implement InitializingBean and DisposableBean interfaces (that are spring specific interfaces), then you are coupling your code with spring. In future if spring renames these interfaces (unlikely though), or you stop using spring you will have to update your class code.

    Instead if you use init-method and destroy-method attributes in your bean config, your class is independent of spring, i.e. there is no depedency of your class on spring specific classes.

    Hope it helps.