Slide 26
Slide 26 text
De
f
inition
Softw
a
re entities (functions, cl
a
sses, modules, etc.) should be open for extension but closed for modi
f
ic
a
tion.
OCP is
a
ll
a
bout
a
chieving ch
a
nges
a
dding new code, not ch
a
nging the old code th
a
t
a
lre
a
dy works.
Closure cannot be complete. There will always be some change against which the entity is not closed. Thus, the closure
must be strategic. As a developer, make educated guesses about the likely kinds of changes that the application could su
ff
er
over time.
OCP me
a
ns th
a
t we do not w
a
nt to modify the cl
a
ss, i.e., write code into
a
cl
a
ss. Once you cre
a
te
a
cl
a
ss
a
nd put th
a
t
cl
a
ss in
a
production environment, you do not w
a
nt to touch th
a
t cl
a
ss.
OCP c
a
n be s
a
tis
f
ied with
a
simple
a
nd e
ff
ective heuristic: inheritance
26