What if the code is not reusable?
In fact, any code can be reusable. The key point here is if the code you intend to reuse is well-written and follows good patterns for reuse. There are several reasons why code should be considered not ready for reuse:
- The code was not tested before: Before reusing code, it is a good approach to guarantee that it works.
- The code is duplicated: If you have duplicate code, you will need to find each place where it is being used so you only have a single version of the code being reused.
- The code is too complex to understand: Code that is reused in many places needs to be written with simplicity to enable easy understanding.
- The code has tight coupling: This is a discussion related to composition versus inheritance when building separate class libraries. Classes (with interfaces) are usually much easier to reuse than base classes that can be inherited.
In any of these cases, considering a refactoring strategy can...