2016-04-22: beyond solid: the package principles
TRANSCRIPT
Beyond SOLID:The Package Principles
Red Panda Innovation LabsCode Words 2016-04-22
Christian HujerCEO / CTO Nelkinda Software Craft Pvt Ltd
Agenda1.The Four Design Smells2.Origins and Reprise of SOLID3.ACCESS / CASE - The Package Principles
a.Package Cohesion Principlesb.Package Coupling Principlesc.Mnemonics
DefinitionsSoftware Entity
Statement / line / method / class / package / serviceComponent
Logical (model / architecture / design) group of Software EntitiesPackage
Physical (e.g. directory, gem, jar) group of Software EntitiesCollocation
Putting things in the same Component / PackageCohesion
Things that are changed togetherCoupling
Dependency that potentially propagates change
1.The Four Design Smells
The Four Design Smells●Rigidity●Fragility●Immobility●Viscosity
RigidityWhat is Rigidity?
Existing Code that causes Effort (known Effort)What causes Rigidity?
Coupling
Fragility●What is Fragility?
○Existing Code that causes Risk (unknown Effort)●What causes Fragility?
○Coupling○Lack of Cohesion
ImmobilityWhat is Immobility?
The difficulty (extra Effort) to reuse something.Rigidity and Fragility in the context of reuse.
What causes Immobility?CouplingLack of Cohesion
ViscosityWhat is Viscosity?
Continuous extra Effort (Time)What causes Viscosity?
CouplingBad development setup / tools
2.The SOLID Principles
A short reminder
SRP - Single ResponsibilityOCP - Open-ClosedLSP - Liskov SubstitutionISP - Interface SegregationDIP - Dependency Inversion
Reminder of SOLID
Design Principles and Design Patterns (2000)Mentions 10 principles● Principles of Object Oriented Class Design:
OCP, LSP, DIP, ISP● Principles of Package Architecture:
REP, CCP, CRP, ADP, SDP, SAP
Origin of SOLID
3.The Package Principles
The Package PrinciplesPackage Cohesion Principles
REP - Release Reuse EquivalencyCCP - Common ClosureCRP - Common Reuse
Package Coupling PrinciplesADP - Acyclic DependenciesSDP - Stable DependenciesSAP - Stable Abstractions
3.a.Package Cohesion
Principles
Release Reuse Equivalency Principle
“The granule of reuse is the granule of release.”
Reuse === ReleaseBundler / Gems, NPM, Jars / Maven, RPM, APT, Brew...
Common Closure Principle (Cohesion) “Classes that change together belong together.”
⇒ This also is a nice pragmatic definition of cohesion and that cohesive elements should be collocated.I call it: Cohesion Collocation Principle
Common Reuse Principle (Cohesion)
“Classes that aren’t reused together should not be grouped together.”
This is really the inversion of the idea that “Classes that change together belong together.”
3.b.Package Coupling
Principles
Acyclic Dependencies Principle“The dependencies between packages must not form cycles.”
Stable Dependencies Principle“Depend in the direction of stability.”
Stable Abstractions Principle“Stable packages should be abstract packages.”
3.c.Mnemonics
How to remember all this stuff?!
ACCESSYour new mnemonic acronymCombine to SOLID ACCESS
ACCESS Mnemonic AcronymADP - Acyclic DependenciesCCP - Common Closure (Cohesion Collocation)CRP - Common ReuseREP - Release Reuse EquivalencySAP - Stable AbstractionsSDP - Stable Dependencies
CASEA shorter mnemonic acronym
Combine to SOLID CASE
CASE - A new mnemonic acronymCohesion / Common
CCP / CRP Common Closure / ReuseAcyclic
ADP Acyclic DependenciesStability
SAP / SDP Stable Abstractions / DependenciesEquivalence
REP Release Reuse Equivalency
Related TopicsSoftware Architecture and DesignSoftware MetricsClean CodeRefactoringTDD, ATDD and BDDAgile Methods, Scrum, Extreme ProgrammingContinuous Integration / Delivery / Deployment, DevOpsSoftware CraftsmanshipLaw of Demeter / Tell Don’t AskCQS - Command Query SeparationProgramming Paradigms (Functional, Structured, Object-Oriented, Object-
Functional, Logic)
References● SOLID and Package Principles, Design Smells:
Design Principles and Design Patterns (Robert C. Martin, 2000)
● ACCESS mnemonic: Christian Hujer● CASE mnemonic: Christian Hujer and Mark Burns
Thank you!Questions?
Follow me on Twitter:@christianhujer