[ Pobierz całość w formacie PDF ]
.From the Library of Santiago Itzcoatl Salinas Reyna72Chapter 4: Working with EDPsAbstractorSuperclassAbstractInheritanceInterfaceoperation SubclassFigure 4.7 Flipped EDPs as PINboxes.Only one specific combination of concepts will get us to where we wish to be.This is the magic behind design patterns: through trial and error, we can find thebest-practice solutions to problems we keep running into.We can write down thesesolutions as a combination of smaller concepts that can be reused and sculptedinto new forms while retaining the wisdom of the original conceptual connections.EDPs allow us to build our best-practice solutions out of primary blocks instead ofthrough trial and error.Another point to be made is that Figure 4.2 shows the absolute minimum UMLthat satisfies the EDPs in the PINboxes, not the exact solution.This is not the imple-mentation; this is one implementation.Recall that we re giving ourselves a way oftalking about design issues such as patterns without limiting ourselves to a highlyspecific and rigidly defined implementation.We can return to the individual EDPsthat comprise Fulfill Method and look at how they can differ in their implementa-tions yet still be the EDPs we wish them to be.4.1.1 IsotopesAny given design pattern, whether one as small as an EDP or as large as a full-blown pattern such as Decorator, can be implemented in a vast number of waysand still embody the concept being described.This flexibility is a hallmark strengthof design patterns.We call these differing implementations isotopes of the pattern.The name is intended to be congruent with the term elemental.In chemistry, anisotope is a variation of an atom of a particular element.Atoms have three compo-nents: electrons, protons, and neutrons.The protons and neutrons form the nucleusof the atom, and the electrons orbit the nucleus.The number of protons in thenucleus determine what element the atom is, and the electrons determine how thatatom connects and interacts with other atoms.An isotope of an element has thesame proton count as other atoms of that element, and it has the same electronshell structure.Because of these two traits, it behaves chemically the same as otherisotopes of that element.It connects to other atoms in the same way, forms the samebonds, and for most intents and purposes can be considered the same as any otherisotopic atom of that element.From the Library of Santiago Itzcoatl Salinas Reyna734.1 Composition of PatternsInternally, however, an atom of an isotope has a different number of neutrons inthe nucleus.From the outside, it looks and acts the same chemically, but the internaldifferences can cause small, insignificant side effects, like, oh, nuclear fission.Thistends to be rather disruptive.In software, we call this unexpected nuclear fission a crash.An isotope of a design pattern in software is defined similarly.It is an implemen-tation of a design pattern in which the core concepts of the pattern what definethat design pattern to be different from all other design patterns and the externalinterface remain the same.In other words, the roles that must be fulfilled do not differ from the expecteddesign pattern description.2 This is analogous to the electron shells in the atommetaphor and is made explicit in the PINbox notation.All that an external entity,such as another pattern instance or code element, will see are the roles surroundingthe nucleus of the definition.The proton count in an atom is what distinguishes it from all other elementsand places it in a specific position in the periodic table.We have a similar situationwith design patterns, where the problem, solution, and context are unique.Whatthe design pattern does, what it solves, and so on, is its discriminator.It is whatmakes it unique from all other design patterns.Change the problem, and we havea different design pattern.Change the context and, again, the design pattern mustadapt and change into something else.If it s a small change, and the resulting newpattern looks a lot like the original, then we have a variant; if it s a large change,then we may have something wholly new.With EDPs, the analogy to atoms and the periodic table is even stronger,because the axes of design context defined in Section 2.2.4 create a well-definedspace within which we can uniquely place each EDP.This is directly comparable tochemistry s periodic table, which creates a well-defined space in which the elementscan be placed and the properties of those elements can be predicted.The position of an EDP within the method-reliance EDP design space asdefined by the object-, type-, and method-similarity axes in Section 2.2.4 is abso-lute.Alter the value of any one of these three axes and the position within thatspace changes.The original EDP has mutated to another one, and you can predictwhat the properties of the new EDP will be.Change anything else about the EDP,2.If the roles do differ, it indicates a fundamental change to the design pattern.This change is calleda variant of the pattern and is a clue that something very substantial has changed, such as the problembeing solved or the context in which it is occurring.From the Library of Santiago Itzcoatl Salinas Reyna74Chapter 4: Working with EDPshowever, such as how it is expressed in a particular instance, and the EDP staysthe same while the implementation shifts different implementation but the sameproperties.With an isotope, either chemical or in design patterns, what differs is the inter-nal structure.In the atom, it is the neutron count that changes.In the instance ofa design pattern, it is the how that instance was implemented.These can have far-ranging effects, even if they are not immediately identifiable from the outside.Atany moment, an unstable atom can split depending on its neutron count, and at anymoment, a poorly implemented instance of a design pattern may cause a crash, eventhough from the outside it looks fine.The idea of separating the implementation from the external interface is notnew to object-oriented programming, it is quite natural and embedded.The newconcept introduced in isotopes is separating the implementation and interface ofa concept in the same manner.Remember that each design pattern has a series ofroles noted in the participants section that must be fulfilled by portions of animplementation.These roles are the external interface through which the designpattern interacts with other concepts and patterns.The collaborations section describes how these roles interact internally at theconceptual level, but these interactions can be described and discussed indepen-dently of the implementation
[ Pobierz całość w formacie PDF ]