A Target for Refactoring
One of the problems in developing reusable software is that itoften has to be
reorganized or
refactored
[OJ90]. Designpatterns help you determine how to
reorganize a design, and theycan reduce the amount of refactoring you need to
do later.
The lifecycle of object-oriented software has several phases.Brian Foote
identifies these phases as the
prototyping
,
expansionary
, and
consolidating
phases
[Foo92].
Design Patterns: Elements of Reusable Object-Oriented Software
391
The prototyping phase is a flurry of activity as the software isbrought to life
through rapid prototyping and incremental changes,until it meets an initial set
of requirements and reaches adolescence.At this point, the software usually
consists of class hierarchies thatclosely reflect entities in the initial problem
domain. The main kindof reuse is white-box reuse by inheritance.
Once the software has reached adolescence and is put into service, itsevolution
is governed by two conflicting needs: (1) the software mustsatisfy more
requirements, and (2) the software must be more reusable.New requirements usually
add new classes and operations and perhapswhole class hierarchies. The software
goes through an expansionaryphase to meet new requirements. This can't continue
for long,however. Eventually the software will become too inflexible andarthritic
for further change. The class hierarchies will no longermatch any problem domain.
Instead they'll reflect many problemdomains, and classes will define many
unrelated operations andinstance variables.
To continue to evolve, the software must be reorganized in a processknown as
refactoring
. This is the phase in which frameworksoften emerge. Refactoring
involves tearing apart classes into special-and general-purpose components,
moving operations up or down the classhierarchy, and rationalizing the interfaces
of classes. Thisconsolidation phase produces many new kinds of objects, often
bydecomposing existing objects and using object composition instead ofinheritance.
Hence black-box reuse replaces white-box reuse. Thecontinual need to satisfy more
requirements along with the need formore reuse propels object-oriented software
through repeated phases ofexpansion and consolidation
—
expansion as new
requirements aresatisfied, and consolidation as the software becomes more general.
This cycle is unavoidable. But good designers are aware of thechanges that can
prompt refactorings. Good designers also know classand object structures that
can help avoid refactorings
—
their designsare robust in the face of requirement
changes. A thoroughrequirements analysis will highlight those requirements that
Do'stlaringiz bilan baham: |