Sunday, October 27, 2013

The US Constitution and Meyer's Open/Closed Principle

While trying to explain Meyer's Open/Closed Principle to a friend, I scratched my head trying to find a real-world example which illustrates the principle.  An example which will be hard to dispute and easy to grasp.

On my way home from work the news reported on the NSA's latest shenanigans (this time it was spying on German Chancellor Angela Merkel).  My thoughts drifted and I contemplated the US Constitution.

Some facts on the Constitution of the United States (source):
  • It went into effect on March 4, 1789
  • It has been amended twenty-seven times
  • The Bill of Rights (the first 10 amendments) was ratified on December 15, 1791
  • The list of all 27 amendments is worth reviewing and of particular interest are amendments 18 and 21 ('git revert', anyone?)
Imagine that! 224 years: from 13 states to 50; one Civil war, two World wars, and countless other wars; the invention of the light bulb; radio and television; labor laws; civil rights movement; the Great Depression; the lunar landing; Roe vs. Wade; 9/11.  And on it goes - with only 27 amendments.
Damn!  Tell me that ain't cool.

The US Constitution is perhaps the ultimate, time-tested example of Meyer's Open/Closed Principle: Open for extension; but Closed for modifications.

It is also worthwhile to reflect on the procedures for amending the constitution:

Before an amendment can take effect, it must be proposed to the states by a two-thirds vote of both houses of Congress or by a convention (known as an Article V convention) called by two-thirds of the states, and ratified by three-fourths of the states or by three-fourths of conventions thereof, the method of ratification being determined by Congress at the time of proposal. To date, no convention for proposing amendments has been called by the states, and only once—in 1933 for the ratification of the twenty-first amendment—has the convention method of ratification been employed.


As software architects and designers, perhaps we should build similar protections against perpetual refactoring of production quality code.  No, I didn't mean that in the literal sense, but I do advocate investing the time to excavate an existing architecture to uncover its governing principles, and understanding how it can be extended while preserving those principles.
Maybe we'll end up with software as durable as the US Constitution.

No comments:

Post a Comment