1ModelModel--ViewView--ControllerControllerdesign patterndesign patternOverviewOverviewIntroduce concepts: design pattern, CRC Introduce concepts: design pattern, CRC cardscardsIllustrate with modelIllustrate with model--viewview--controller controller patternpatternShow how a programming language Show how a programming language (Java) supports MVC pattern(Java) supports MVC patternDesign PatternsDesign Patterns“Making abstractions which are powerful and deep is an art. It requires tremendous ability to go to the heart of things, and get at the really deep abstraction. No one can tell you how to do it in science. No one can tell you how to do it in design.”– Christopher AlexanderChristopher AlexanderChristopher Alexander““A pattern language actually gives us the powerA pattern language actually gives us the powerto generate these coherent arrangements ofto generate these coherent arrangements ofspace. Thus, as in the case of natural languages,space. Thus, as in the case of natural languages,the pattern language is generative. It not onlythe pattern language is generative. It not onlytells us the rules of arrangement, but shows ustells us the rules of arrangement, but shows ushow to construct arrangements how to construct arrangements ——as many as we want as many as we want ——which satisfy the rules. . . When a person is faced with an which satisfy the rules. . . When a person is faced with an act of design, what he does act of design, what he does is governed entirelyis governed entirelyby the by the pattern language which he has in his mind at that moment... pattern language which he has in his mind at that moment... His act of design, whether humble, or gigantically complex, His act of design, whether humble, or gigantically complex, is is governed entirely bygoverned entirely bythe patterns he has in his mind at that the patterns he has in his mind at that moment, and his ability to combine these patterns to form a moment, and his ability to combine these patterns to form a new design.new design.””––Christopher AlexanderChristopher Alexander2Software design patternsSoftware design patternsStarting in the late 80Starting in the late 80’’s, OO researchers developed s, OO researchers developed the idea that software design was like other design the idea that software design was like other design disciplines and could benefit from recognizing disciplines and could benefit from recognizing common, successful design patterns.common, successful design patterns.Classic book: Classic book: Design Patterns: Elements of Reusable ObjectDesign Patterns: Elements of Reusable Object--Oriented SoftwareOriented Software; Erich Gamma, Richard Helm, Ralph ; Erich Gamma, Richard Helm, Ralph Johnson, and John Johnson, and John VlissidesVlissides; Addison; Addison--Wesley, 1995 Wesley, 1995 Good starting point: Good starting point: http://hillside.net/http://hillside.net/Basic idea: competent software designer is familiar Basic idea: competent software designer is familiar with a large set of design patterns that with a large set of design patterns that ““work wellwork well””..When presented with a new problem, you should When presented with a new problem, you should start by selecting one or more patterns that start by selecting one or more patterns that ““fitfit””the the problem.problem.Why Use Patterns?Why Use Patterns?They have been proven.They have been proven.Patterns reflect the Patterns reflect the experience, knowledge and insights of experience, knowledge and insights of developers who have successfully used them.developers who have successfully used them.They are reusable.They are reusable.Patterns provide a readyPatterns provide a ready--made solution that can be adapted to different made solution that can be adapted to different problems as necessary.problems as necessary.They are expressive.They are expressive.Patterns provide a Patterns provide a common vocabulary of solutions that can common vocabulary of solutions that can express large solutions succinctly.express large solutions succinctly.Support for PatternsSupport for PatternsThe abstraction mechanisms inherent in The abstraction mechanisms inherent in OO languages are ideal for implementing OO languages are ideal for implementing patterns.patterns.As we will see, the Java Observer interface As we will see, the Java Observer interface and Observable class (in and Observable class (in java.util) provide provide useful tools to implement the modeluseful tools to implement the model--viewview--controller pattern.controller pattern.CMSC 446 Intro to Design PatternsCMSC 446 Intro to Design PatternsMW 7pm, Spring 2004, Bob MW 7pm, Spring 2004, Bob TarrTarrThis course is an introduction to software design patterns. Each pattern represents a best practice solution to a software problem in some context. The course will cover the rationale and benefits of object-oriented software design patterns. Several example problems will be studied to investigate the development of good design patterns. Specific patterns, such as Observer, State, Adapter, Strategy, Decorator and Abstract Factory will be discussed. Programming projects in the Java language will provide experience in the use of these patterns. In addition, distributed object frameworks, such as RMI and Jini, will be studied for their effective use of design patterns.3The MVC patternThe MVC patternMVC stands for ModelMVC stands for Model--ViewView--ControllerControllerOriginally developed by Smalltalk hackersOriginally developed by Smalltalk hackersThe Model is the actual internal The Model is the actual internal representationrepresentationThe View (or a View) is a way of The View (or a View) is a way of looking at or displaying the modellooking at or displaying the modelThe Controller provides for user input The Controller provides for user input and modificationand modificationModelViewControllerThe ModelThe ModelMost programs are supposed to do work, Most programs are supposed to do work, not just be "another pretty face"not just be "another pretty face"but there are some exceptionsbut there are some exceptionsuseful programs existed long before GUIsuseful programs existed long before GUIsThe The ModelModelis the part that does the workis the part that does the workThe Model should be
View Full Document