principles:encapsulate_the_concept_that_varies
This is an old revision of the document!
Table of Contents
Encapsulate the Concept that Varies (ECV)
Variants and Alternative Names
Context
Principle Statement
Encapsulate the Concept that Varies, i.e. a design is better when those parts that vary are encapsulated in a separate module.
Description
Rationale
Strategies
Origin
Evidence
Relations to Other Principles
Generalizations
Specializations
- Single Responsibility Principle (SRP): A responsibility in the sense of SRP is defined as “a reason for change”. This is a concept that varies over time. SRP tells that each module should have exactly one responsibility, i.e. the concept/responsibility should be encapsulated in that module.
- Open-Closed Principle (OCP): The OCP demands encapsulating abstract concepts in base classes (or interfaces) in order to be able to enhance the module by subclassing which is possible without changing the previously written code. In this case several variations of a concept may exist in the code at the same time. There is always the abstract base class plus one or usually more concrete subclasses. So the OCP is about encapsulating abstract concepts that vary “in space”.
Contrary Principles
- More Is More Complex (MIMC): ECV demands adding a new class for a new varying concept.
- Keep It Simple Stupid (KISS): ECV demands adding a new class for a new varying concept. This adds complexity.
- Model Principle (MP): ECV sometimes results in classes which do not correspond top a real-world concept in the sense of MP. A “concept that varies” can also be a technical concept.
Complementary Principles
- Dependency Inversion Principle (DIP): ECV may result in the creation of abstract classes (i.e. the concepts) and descendant concrete classes (i.e. the variations). DIP now tells that other classes should only depend on the abstractions.
Principle Collections
Example
Description Status
Further Reading
- Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides: Design Patterns: Elements of Reusable Object-Oriented Software, p. 29
- Bertrand Meyer: Object-Oriented Software Construction, p. 57pp.
- Robert C. Martin: Agile Software Development, Principles, Patterns, and Practices, p. 99pp.
principles/encapsulate_the_concept_that_varies.1359539076.txt.gz · Last modified: 2013-05-20 12:46 (external edit)