Open/closed principle

Open/closed principle

In object-oriented programming, the open/closed principle states "software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification";[1] that is, such an entity can allow its behaviour to be modified without altering its source code. This is especially valuable in a production environment, where changes to source code may necessitate code reviews, unit tests, and other such procedures to qualify it for use in a product: code obeying the principle doesn't change when it is extended, and therefore needs no such effort.

The name Open/Closed Principle has been used in two ways. Both ways use inheritance to resolve the apparent dilemma, but the goals, techniques, and results are different.

Contents

Meyer's Open/Closed Principle

Bertrand Meyer is generally credited as having originated the term Open/Closed Principle,[citation needed] which appeared in his 1988 book Object Oriented Software Construction. The idea was that once completed, the implementation of a class could only be modified to correct errors; new or changed features would require that a different class be created. That class could reuse coding from the original class through inheritance. The derived subclass might or might not have the same interface as the original class.

Meyer's definition advocates implementation inheritance. Implementation can be reused through inheritance but interface specifications need not be. The existing implementation is closed to modifications, and new implementations need not implement the existing interface.

Polymorphic Open/Closed Principle

During the 1990s, the Open/Closed Principle became popularly redefined to refer to the use of abstracted interfaces, where the implementations can be changed and multiple implementations could be created and polymorphically substituted for each other.

In contrast to Meyer's usage, this definition advocates inheritance from abstract base classes. Interface specifications can be reused through inheritance but implementation need not be. The existing interface is closed to modifications and new implementations must, at a minimum, implement that interface.

Robert C. Martin's 1996 article "The Open-Closed Principle"[2] was one of the seminal writings to take this approach. In 2001 Craig Larman related the Open/Closed Principle to the pattern by Alistair Cockburn called Protected Variations, and to the David Parnas discussion of information hiding[3].

See also

  • SOLID – the "O" in "SOLID" stands for the open/closed principle

References

  1. ^ Meyer, Bertrand (1988). Object-Oriented Software Construction. Prentice Hall. ISBN 0136290493. 
  2. ^ Robert C. Martin "The Open-Closed Principle", C++ Report, January 1996
  3. ^ "Protected Variation: The Importance of Being Closed", IEEE Software May/June 2001, pp. 89-91 [1]

External links


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать реферат

Look at other dictionaries:

  • Open-Closed Principle — Das Open Closed Principle ( Offen Geschlossen Prinzip , kurz OCP) ist ein Prinzip beim Objektorientierten Entwurf von Software. Es beschäftigt sich mit der Erweiterbarkeit von bestehender Software. Im allgemeinen wird das OCP beschrieben durch:… …   Deutsch Wikipedia

  • Open list — Part of the Politics series Electoral methods Single winner …   Wikipedia

  • Open source software development — is the process by which open source software (or similar software whose source code is publicly available) is developed. These are software products “available with its source code and under an open source license to study, change, and improve… …   Wikipedia

  • Open Data — is a philosophy and practice requiring that certain data are freely available to everyone, without restrictions from copyright, patents or other mechanisms of control. It has a similar ethos to a number of other Open movements and communities… …   Wikipedia

  • Open source software security — is the measure of assurance or guarantee in the freedom from danger and risk inherent to an open source software system. Contents 1 The debate 1.1 Benefits of open source security 1.2 Drawbacks of open source security …   Wikipedia

  • Open problem — Open question redirects here. For information on open ended questions, see closed ended question. In science and mathematics, an open problem or an open question is a known problem that can be accurately stated, and has not yet been solved (no… …   Wikipedia

  • principle — principle, axiom, fundamental, law, theorem are comparable when they denote a proposition or other formulation stating a fact or a generalization accepted as true and basic. Principle applies to a generalization that provides a basis for… …   New Dictionary of Synonyms

  • Open Access — Open Access.net Logo Als Open Access (englisch für offener Zugang) wird der freie Zugang zu wissenschaftlicher Literatur und anderen Materialien im Internet bezeichnet. Ein wissenschaftliches Dokument unter Open Access Bedingungen zu publizieren… …   Deutsch Wikipedia

  • Liskov substitution principle — In object oriented programming, the Liskov substitution principle is a particular definition of subtype that was introduced by Barbara Liskov in a 1987 conference keynote address entitled Data abstraction and hierarchy ] as follows:: Let q(x) be… …   Wikipedia

  • Open source — This article is about the production and development model. For its application to software, see Open source software. For the form of intelligence collection management, see Open source intelligence. For other uses, see Open source… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”