Students often picture software engineering as "build the system, hand it over, done". In reality, delivery is the start of most software's life. Your college's admission portal was probably written years ago, and every year someone changes the fee structure, adds a new quota, fixes a payment bug or moves it to a new server. All of that is maintenance, and for long-lived systems it usually costs far more than the original development.
In this chapter we define maintenance and its types (including the categories in the current ISO/IEC/IEEE 14764:2022 standard), see why software must keep changing (Lehman's laws), estimate maintenance effort, and then look at what to do when a system becomes old and painful: reverse engineering, refactoring and reengineering, with a small runnable example.
Software maintenance is the modification of a software product after delivery to correct faults, to improve performance or other attributes, or to adapt the product to a changed environment.
Why Software Needs Maintenance
Code does not wear out (we saw this in Software Reliability), so why does it need constant attention? Because the world around it changes:
Bugs surface in the field that testing missed.
The environment changes: a new Android version, a new browser, a database upgrade, a payment gateway that retires its old API.
Rules change: new GST rates, a new government scholarship scheme, data-protection laws such as India's DPDP Act.
Users want more: once people use a system, they discover features they want.
The code itself decays: quick fixes pile up and make the next change harder.
Commonly cited studies put maintenance at well over half, often 60–80%, of total lifetime cost for long-lived systems. The exact figure varies, but the lesson does not: designing for maintainability (low coupling, high cohesion, clear names, tests) from Modularity, Coupling & Cohesion pays off for years.
Types of Maintenance
The classic classification, from Lientz and Swanson (1980) with preventive maintenance added later, has four types:
| Type | Purpose | Trigger | Fee-portal example |
|---|---|---|---|
| Corrective | Fix faults discovered after delivery | Failure reports from users | Receipt shows wrong total when a concession applies |
| Adaptive | Keep the software usable in a changed environment | New OS, hardware, platform, regulation or external interface | Switch to the payment gateway's new API version |
| Perfective | Improve performance, usability or maintainability; meet new user needs | User requests, performance complaints | Make the fee page load in 1 s instead of 6 s; add UPI QR payment |
| Preventive | Detect and fix latent faults before they cause failures; make future maintenance easier | Code reviews, static analysis, ageing code | Fix a date-handling bug that will only fail next leap year; refactor a 900-line function |
Lientz and Swanson's survey found that most effort went into perfective work (roughly half), followed by adaptive (about a quarter), with corrective maintenance only around a fifth. So most "maintenance" is really evolution, not bug fixing.
The current standard: ISO/IEC/IEEE 14764:2022
The maintenance standard groups the maintenance types into corrections and enhancements:
Maintenance
├── Correction (fixing problems)
│ ├── Corrective – reactive fix of a discovered problem
│ ├── Preventive – fix latent faults before they become failures
│ └── Emergency – unscheduled, urgent fix to keep the system
│ running (a kind of corrective maintenance)
└── Enhancement (not a correction)
├── Adaptive – keep the product usable in a changed environment
├── Perfective – improve performance, maintainability, other attributes
└── Additive – add new functionality
Two names go beyond the classic four. Emergency maintenance (already in the earlier 2006 edition) is an unscheduled corrective change made to keep the system operational until a proper fix is ready. Additive maintenance, distinguished in the 2022 edition, separates adding new functionality from perfective work (improving existing qualities such as performance or maintainability). Most university syllabi still ask for the four classic types; give those, and mention the 2022 refinement for extra credit.
Lehman's Laws of Software Evolution
Manny Lehman studied how large systems such as IBM's OS/360 evolved over many releases. He separated S-type programs (fully specified, e.g. a sorting routine), P-type (solving an approximate real problem, e.g. chess) and E-type programs (embedded in the real world, e.g. a banking or ERP system). His laws apply to E-type systems:
| # | Law | In plain words |
|---|---|---|
| I | Continuing change | A system in use must keep changing, or it becomes progressively less useful. |
| II | Increasing complexity | As it changes, its complexity grows unless work is done to reduce it. |
| III | Self-regulation | Evolution of large systems follows statistically regular trends. |
| IV | Conservation of organisational stability | The average effective rate of work on an evolving system stays roughly constant over its life. |
| V | Conservation of familiarity | The amount of change per release stays roughly constant, because people must understand each release. |
| VI | Continuing growth | Functionality must keep growing to keep users satisfied. |
| VII | Declining quality | Quality will appear to decline unless the system is actively maintained and adapted. |
| VIII | Feedback system | Evolution is a multi-level, multi-loop feedback process and must be treated as such. |
Law II is the reason preventive maintenance and refactoring exist: complexity grows by default, and only deliberate effort pushes it back down.
The Maintenance Process
A typical change follows the same small life cycle each time:
Change request ──► Impact analysis ──► Approve? ──► Plan release
(bug report, (what modules, (change │
new need) tests, effort, control board) ▼
risk?) Implement change
│
Release ◄── Regression test ◄──────┘
│
└──► update documentation and baselines
Program comprehension is usually the biggest cost: maintainers often spend more time understanding the code than changing it.
Impact analysis finds everything a change could affect (callers, data, tests, documents).
Regression testing (from Levels of Testing) checks that the change has not broken existing behaviour.
Approval, versions and baselines are managed through Software Configuration Management, the next chapter.
Maintenance process models
| Model | Idea | Risk |
|---|---|---|
| Quick-fix | Patch the code directly, update docs later (or never) | Fast now, but structure and documentation decay quickly |
| Iterative enhancement | Analyse the existing system, then redesign and implement changes through the full cycle, updating all documents | Needs complete, current documentation |
| Reuse-oriented | Treat the old system as a source of reusable components for a new one | Needs a good component library and understanding |
Estimating Maintenance Effort
Boehm proposed a simple estimate based on Annual Change Traffic (ACT), the fraction of the code that is added or modified in a year:
ACT = (KLOC added + KLOC modified per year) / total KLOC
Annual maintenance effort = ACT × development effort
(In the COCOMO model this can be multiplied further by an effort adjustment factor; see COCOMO Model.)
Worked example
A 20 KLOC hostel management system took 600 person-months to develop. Each year about 2 KLOC are added and 1 KLOC modified.
ACT = (2 + 1) / 20 = 0.15
Effort = 0.15 × 600 = 90 person-months per year (= 7.5 people full time)
Maintainability Index
A widely used metric that combines Halstead volume (V), cyclomatic complexity (G) and lines of code (from Software Quality & Metrics and White-Box Testing & Cyclomatic Complexity) is the Maintainability Index of Oman and Hagemeister:
MI = 171 − 5.2 ln(V) − 0.23 G − 16.2 ln(LOC)
(> 85 highly maintainable, 65–85 moderate, < 65 difficult to maintain)
Module A: V = 1000, G = 10, LOC = 100 → MI ≈ 58.2 (difficult)
Module B: V = 200, G = 2, LOC = 20 → MI ≈ 94.5 (highly maintainable)
Some tools (Visual Studio, for example) rescale it to 0–100 as max(0, MI × 100 / 171), so the same Module A shows as about 34 there. Always check which scale a tool uses before comparing numbers.
Legacy Systems
A legacy system is an older system that is still essential to the business but is hard to change, often because of obsolete technology, missing documentation, departed developers and years of patches.
Banks running COBOL, a university's results system written in an old version of PHP, or a railway booking engine are typical examples. Throwing them away is risky because they contain decades of business rules that nobody fully remembers. Sommerville suggests assessing each system on two axes:
BUSINESS VALUE
low high
┌────────────────────┬────────────────────┐
high │ Replace with an │ Continue normal │
│ off-the-shelf │ maintenance │
SYSTEM │ product, scrap or │ │
QUALITY │ just maintain │ │
├────────────────────┼────────────────────┤
low │ Scrap │ REENGINEER, or │
│ │ replace if a good │
│ │ product exists │
└────────────────────┴────────────────────┘
The bottom-right box, valuable but badly built, is where reengineering is worth its cost.
Reverse Engineering, Refactoring and Reengineering
These terms sound alike but mean different things:
| Term | Direction | What it does | Changes behaviour? |
|---|---|---|---|
| Reverse engineering | Code → design/requirements | Analyses an existing system to recover higher-level descriptions (structure charts, data models, UML) | No, it changes nothing |
| Restructuring | Same level | Transforms code or data into a better form at the same abstraction level | No |
| Refactoring | Same level, small steps | Restructuring of code in small, behaviour-preserving steps backed by tests (Fowler's term) | No |
| Forward engineering | Requirements → design → code | The normal development direction; in reengineering, rebuilding from the recovered design | May add improvements |
| Reengineering | All of the above | Reverse engineering + restructuring + forward engineering to produce an improved system | Functionality usually kept; quality improved |
reverse engineering forward engineering
legacy code ──────────────► recovered design ──────────────► new system
│ (+ restructured, ▲
│ improved design) │
└──────────── REENGINEERING = the whole round trip ─────────┘
The software reengineering process
Pressman describes reengineering as a cycle of six activities, which need not happen strictly in order:
Inventory analysis: list all applications with size, age, business criticality and maintainability; pick candidates for reengineering.
Document restructuring: decide how much documentation to recreate (all, only for changed parts, or none for stable systems).
Reverse engineering: recover design, data and processing information from the code.
Code restructuring: rewrite poorly structured modules into structured, readable code with the same behaviour.
Data restructuring: analyse and redesign data structures or database schemas (for example, normalising old flat files into tables).
Forward engineering: rebuild the system using modern practices from the recovered information, improving quality.
Strangler fig: modern incremental replacement
A "big bang" rewrite of a legacy system often fails because the old system keeps changing during the rewrite. The strangler fig pattern (named by Martin Fowler) replaces it gradually: put a routing layer in front, move one feature at a time to the new system, and route that feature's traffic there, until the old system can be switched off.
Step 1: users ─► router ─► LEGACY (all features)
Step 2: users ─► router ─┬► NEW (fee payment)
└► LEGACY (everything else)
Step 3: users ─► router ─► NEW (all features) legacy retired
Refactoring in Practice
Here is a function from an imaginary legacy fee module. It works, but the magic numbers and duplicated branches make every fee change risky.
# legacy.py
def calc(d):
t = 0
for i in d:
if i[1] == "UG":
if i[2] == "SC" or i[2] == "ST":
t = t + 45000 - 45000 * 0.5
else:
t = t + 45000
else:
if i[2] == "SC" or i[2] == "ST":
t = t + 60000 - 60000 * 0.5
else:
t = t + 60000
return t
Refactoring steps, each small and safe: rename (calc → total_fees), replace magic numbers with named constants/tables, extract function (fee_for), and remove duplication.
# fees.py
BASE_FEE = {"UG": 45000, "PG": 60000}
CONCESSION = {"SC": 0.5, "ST": 0.5} # fraction waived
def fee_for(programme, category):
base = BASE_FEE[programme]
return base * (1 - CONCESSION.get(category, 0))
def total_fees(students):
return sum(fee_for(prog, cat) for _, prog, cat in students)
The golden rule of refactoring: behaviour must not change, and a test proves it.
# test_refactor.py
from legacy import calc
from fees import total_fees
students = [("Asha", "UG", "GEN"), ("Ravi", "UG", "SC"),
("Meena", "PG", "OBC"), ("Kiran", "PG", "ST")]
print("legacy :", calc(students))
print("refactored:", total_fees(students))
assert calc(students) == total_fees(students)
print("Behaviour preserved")
Output:
legacy : 157500.0
refactored: 157500.0
Behaviour preserved
(45000 + 22500 + 60000 + 30000 = 157500.) Now the next change, say adding a 25% concession for the EWS category or a new "PhD" programme, is a one-line edit to a table instead of a new pair of nested branches. That is exactly what preventive and perfective maintenance aim for.
Technical debt
Ward Cunningham's metaphor: taking a shortcut is like borrowing money. You ship faster today, but you pay interest on every later change (extra time spent working around the messy code) until you repay the principal by refactoring. A little debt taken deliberately can be sensible; unmanaged debt eventually makes every change slow and risky, which is how systems become legacy.
Common Mistakes
Equating maintenance with bug fixing. Most maintenance effort is perfective and adaptive.
Confusing adaptive and perfective. Adaptive responds to a change in the environment; perfective improves the product or adds what users want.
Calling any rewrite "refactoring". Refactoring preserves behaviour and proceeds in small tested steps.
Thinking reverse engineering modifies the system. It only extracts information.
Skipping regression tests after a "small" fix. Small fixes are a major source of new faults.
Quick-fixing without updating documents and baselines. The next maintainer inherits code that no longer matches its documentation.
Interview and Exam Questions
Q1. Classify each change: (a) supporting a new browser version, (b) fixing wrong GPA rounding, (c) making search 5× faster, (d) cleaning up code that is likely to fail at year-end.
(a) Adaptive, (b) Corrective, (c) Perfective, (d) Preventive.
Q2. A 50 KLOC system cost 1000 person-months to build. Each year 4 KLOC is added and 6 KLOC modified. Estimate annual maintenance effort.
ACT = (4 + 6) / 50 = 0.2. Effort = 0.2 × 1000 = 200 person-months per year.
Q3. Differentiate reverse engineering, reengineering and refactoring.
Reverse engineering recovers design information from code without changing it. Refactoring makes small behaviour-preserving improvements to code structure. Reengineering is the larger process: reverse engineer a system, restructure it and forward engineer an improved version.
Q4. State any four of Lehman's laws.
Continuing change (systems must change or become less useful), increasing complexity (complexity grows unless reduced), continuing growth (functionality must grow), declining quality (quality appears to decline unless actively maintained). Others: self-regulation, conservation of organisational stability, conservation of familiarity, feedback system.
Q5. When should a legacy system be reengineered rather than replaced or scrapped?
When it has high business value but low technical quality, and no suitable off-the-shelf product exists. Low-value, low-quality systems should be scrapped; high-value, high-quality ones simply maintained.
Q6. What is technical debt and how do teams manage it?
The future cost of shortcuts taken now. Teams track it (e.g. in the backlog), set aside capacity each sprint for refactoring, use static analysis to spot hotspots, and pay it down where change is frequent.
Summary
Maintenance is modification after delivery, and usually the largest share of lifetime cost.
Four classic types: corrective, adaptive, perfective, preventive. ISO/IEC/IEEE 14764:2022 groups them into corrections (corrective, preventive, emergency) and enhancements (adaptive, perfective, additive).
Lehman's laws: E-type systems must keep changing and growing, and their complexity and quality worsen unless actively managed.
Effort estimate: ACT × development effort. The Maintainability Index combines Halstead volume, cyclomatic complexity and LOC.
Legacy systems: assess business value vs quality; reengineer high-value, low-quality ones.
Reengineering = reverse engineering + restructuring + forward engineering; Pressman's six activities run from inventory analysis to forward engineering.
Refactoring preserves behaviour, proven by tests; the strangler fig pattern replaces systems incrementally.
Next, Software Configuration Management shows how all these changes are identified, controlled, versioned and audited.