News:

This week IPhone 15 Pro winner is karn
You can be too a winner! Become the top poster of the week and win valuable prizes.  More details are You are not allowed to view links. Register or Login 

Main Menu

c++ Tips - The open/closed principle

Started by ben2ong2, October 07, 2006, 04:05:57 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

ben2ong2

PROBLEM: You are not allowed to view links. Register or Login (Dave Jones)

"Open/closed principle"  ... what is it, and who first buzzed the words?


RESPONSE: You are not allowed to view links. Register or Login (Justin Forder), 18 May 93

Bertrand Meyer, in "Object-oriented Software Construction", page 23:

"The Open-Closed Principle

A satisfactory modular decomposition technique must satisfy one more
requirement: it should yield modules that are _both_ open and closed.

- A module will be said to be open if it is still available for extension.
  For example, it should be possible to add fields to the data structures
  it contains, or new elements to the set of functions it performs.

- A module will be said to be closed if it is available for use by other
  modules. This assumes that the module has been given a well-defined,
  stable description (the interface in the sense of information hiding).
  In the case of a programming language module, a closed module is one
  that may be compiled and stored in a library, for others to use.
  In the case of a design or specification module, closing a module
  simply means having it approved by management, adding it to the project's
  official repository of accepted software items (often called the project
  _baseline_), and publishing its interface for the benefit of other
  module designers."

Meyer goes on to give an example, and to explain how the tension between
delivering stable items to their users, on the one hand, and maintaining
extensibility, on the other, gives real problems in classical development
approaches. With inheritance and polymorphism, a class can be closed (in
the sense that it is complete and delivers what its interface description
promises) and open (because you can specialise it). When new subclasses are
introduced, neither the original class nor its clients need to be edited or
recompiled.


You are not allowed to view links. Register or Login
You are not allowed to view links. Register or Login