Code Reusability in Software Programming

Miquel Canal

Tuesday 2, March 2021
  • Software Engineering
  • Software Architecture
  • Software Patterns

What is reusable code?

In software programming, reusable code refers to the use of the same source code collection in multiple applications or systems.

At its best, code reuse is accomplished by sharing common classes or collections of functions and procedures (this is possible in C++, but not in Smalltalk or Java). At its worst, code reuse is accomplished by copying and then modifying existing code.

There are multiple ways to write reusable code. In this article we are going to review the most common reusable code patterns.

Reusable code in Object Oriented Programming

Back in the origins of object-oriented programming, object classes were thought to be reusable for any future project under any circumstance. This, however, hasn’t been the case as code reusability is a difficult technique that is not suitable for all programming scenarios.

Object Oriented Programming is based on objects. Objects are represented by interfaces which specify the properties of the objects. The goal to code reusability in Object-Oriented Programming is to design objects in a way that can later on be used on other systems.

The truth about code reusability is that software projects frequently overrun their budgets and software is developed behind the planned schedule. This pressure on development can lead to code that is not clean becoming less reusable.

Reusable components

The evolution to object reusability is the concept of component reusability. A component is a unit that can be reused or replaced. The ideal software applications are built using connections of components.

According to the Catalysis Approach, a component can be reused when:

Reuse code using libraries

The next step on this code reusability journey is to review code libraries. It was believed that OOP would create tons of libraries and that libraries won’t require programmers any more, just connecting existing libraries. However, that hasn’t been the case.

Too many developers underestimate the difficulty of producing a usable library, while overestimating their own ability to do so. Objects deliver better semantics, organization of code/functionality and, possibly, ease-of-use. Well designed libraries deliver on the promise of code reuse, not objects per se.

The most successful code libraries tend to be small and full-filling a well defined purpose, rather than trying to satisfy multiple needs. Libraries need to have a well documented APIs so the reusability can be done without direct access to the source code.

Benefits of code reuse

Richard John Anthony wrote key benefits of reusing code in its book Systems Programming (2016):

Reusable code problems

As with everything in software programming, there are also cons of using code reusability approach. Here are a couple of examples:

Reusable Knowledge in Software Programming

While doing my research for this article I came across the “Reusable Knowledge” term. This has changed my way of thinking about code reuse.

Due to difficulties attached to code reusability the “reuse of knowledge” concept has been researched. Instead of reusing the lines of code what it is being reused is the knowledge on how to build a system taking into account past experiences.

An ongoing research is the KnowBench architecture. The concept lies on capturing knowledge from building a software system and applying it on future developments. Documentation is key to this type of reusability. This research uses Semantic Web technologies to generate annotations that capture knowledge and experiences that can prevent the repetition of past failures in future software development projects.

Another example of knowledge reuse in software systems is the idea of applying program transformation to a set of knowledge concepts and transforming it into software.

The code reusability journey is far from over. It will be an exciting topic to follow in the upcoming years as new and powerful technologies are constantly raising.


Domain Driven Design (DDD)

Domain Driven Design (DDD)

What is Domain Driven Design and why it is important to define a clear terminology? This article covers the key aspects of developing software following best practices of Domain Driven Design.

Introduction to Algorithm Complexity Analysis

Introduction to Algorithm Complexity Analysis

A basic but helpul introduction to Algorithm Complexity Analysis. An overview of tools for analysing algorithms and representing their complexity.

The 12-Factor methodology

The 12-Factor methodology

The twelve-factor app is a methodology used to build software-as-a-service apps that are easy to scale up without significant changes to tooling or architecture.

This site uses cookies to ensure a great experience. By continue navigating through the site you accept the storage of these cookies.