Why and what is software design?Software design principles Design patternsModel-View-ControllerSummaryOutlineSoftware Design PatternTo Encapsulate Changes Anticipation of ChangesChange is inevitable and frequentChanges can be anticipatedChanges should be isolatedA General Definition of PatternEach pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice. A Pattern Language: Towns, Buildings, Construction,Christopher Alexander, et al, Oxford University Press, 1977Design Patterns OverviewStructural patterns(7)AdapterBridgeCompositeDecoratorFa?adeFlyweightProxyCreational patterns(5)Abstract FactoryBuilderFactory PrototypeSingletonDesign Patterns OverviewObserverStateStrategyTemplate MethodVisitorBehavioral patterns(11)Chain of responsibilityCommandInterpreterIteratorMediatorMementorAbout CreationFamily of Classes ? FactoryThe Maze GameWhat if we wanted to have enchanted mazes with EnchantedRooms and EnchantedDoors? Or a secret agent maze with DoorWithLock and WallWithHiddenDoor?Significant changes to the createMaze() method due to explicit instantiations using new operatorThe “Simple” codeSlightly more complex,A lot more FLEXIBLE!!Replace new operator with make methodsThe Open-Close Principle:Open for extension,Close for modificationThe Factory MethodFactory MethodIntentDefine an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses. ApplicabilityA class cannot participate the class of objects it must createA class wants its subclasses to specify the objects it createsClasses delegate responsibility to one of several helper subclasses, and it is desirable to localize the knowledge of which helper subclass is the delegateFactory MethodParticipantProduct: Define the interface of objects
原创力文档

文档评论(0)