Factors Improving Code Reuse

What principles, code qualities, practices, approbations, language or structure functions help you reuse functions, classes, etc. in a wider range of cases. All situations are interesting: either you can change both the implementation and the code interface to enable / improve reuse, or just the implementation, or nothing at all. Key indicators of reuse efficiency are (as for me):

  • how much it reduces efforts for implementation and maintenance.
  • application quality does not deteriorate
  • how complicated is the procedure

(all compared to overriding from a lower level).

PS. If possible, indicate one factor per answer describing how it helps in your case.

+5
source share
4 answers

Test Driven Development . For code to be easily tested, it must:

1) do only one thing

2) have as few dependencies as possible

3) often have those dependencies that were transmitted (so that they can be mocked)

By surprising coincidence, these factors also make for reusable code. Actually, this is not a coincidence - the best way to get a reusable code is to ensure that it is used by at least two subscribers as early as possible. Code created using TDD starts life with two parents — code under construction and unit tests, so it is reused from the very beginning.

TDD , - , , . TDD , , , .

+3

- coupling . , ( ), , , , ..

+5

, , . - , , output

+2

, , .
, , .

, / , :

  • ( , ).
  • ( )
  • ( , )
  • ( , . , )
  • Test-Driven-Development .

, . , . , , .

The main thing is that the issue of reuse is associated more with personality than with technology .

+2
source

All Articles