In Robert Glass’ Facts and Fallacies of Software Engineering he presents his “Rules of Three” when it comes to writing reusable components.
1) It is three times as difficult to build reusable components as single use components.
2) A reusable component should be tried out in three different applications before it will be sufficiently general to accept into a reuse library.
The first thing I like about these rules is that they are implicitly saying, “It is perfectly OK to write single use components.” These days I think a lot of developers minds spend a lot of cycles on reusability and API writing when they don’t really need to. This paralysis keeps them from completing a great product in a shorter amount of time.
Rule two is more powerful than rule one. You might be able to weasel an extra two days into the schedule for the larger project so you can get your fix and write a reusable component. You might. But you aren’t going to be able to shoehorn the component into 2 other places it doesn’t really belong without someone noticing. If you agree with Glass’ rules, you can see these two corollaries.
1a) Assuming difficulty = time, if you don’t have three times the time budget you would need to build a single use component, build the single use component.
2a) If you don’t have three real applications where you can use this reusable component, build the single use component.
These are easier to follow when trying to make decisions because they give you concrete tests to pass before you set down the path for the holy grail of reusability.
