Unformatted text preview:

Model View Controller PatternFolding Intra-Class PatternScanning Inter-Class PatternArchitectural PatternBook on Design PatternsMVC PatternDisplaying PointsSlide 8Slide 9ObjectEditor-based StructureReusing Point HistoryMore Modular ApproachSharing the ViewSharing the ControllerController Without ViewView Without ControllerMonolithic EditorSeparate View and ControllerMultiple Views and ControllersModel View Controller FrameworkSlide 21Class Vs InstanceMVC FrameworkModelModel Vs PointHistoryReusing PointHistoryNotification SchemeView with Multiple ModelsGeneral Notification SchemePointHistoryModel & PointHistoryListenerAPointHistoryModelConsole ViewSlide 33Console ControllerConsole ComposerSlide 36Using a More Specific TypeUsing Most General Type PossibleModel View Controller Pattern•Patterns•Model-View-ControllerA Single Class T result = I;T nextValue = getNextValue()while (!isSentinel(nextValue)) { result = f(result, nextValue); nextValue = getNextValue(..);}Folding Intra-Class PatternLoan, intnew ALoan(0), 1ALoan.add(), *>= 0Scanning Inter-Class PatternScanner InstanceEnumeration InterfaceScanner Userpublic interface <Type>Enumeration { public <Type> nextElement(); public boolean hasMoreElements();}Architectural Pattern•Christopher 79–Each pattern is a three part rule, which expresses a relation between a certain context, a problem, and a solution.–Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of a solution to that problem, in such a way that you can use this solution a million times overBook on Design PatternsMVC PatternModel:APointHistoryModel instanceController:AConsoleControllerinstanceController:AnAWTControllerinstanceController:AnAWTControllerinstanceController:ASwingControllerinstanceView:AConsoleViewinstanceView:ABarChartViewinstanceView:APlotterViewinstanceView:AplotterviewinstanceDisplaying PointsDisplaying PointsSwing buttonAWT buttonSwing Detachable ToolbarDisplaying PointsAll four views displayed concurrently and kept in Sync.ObjectEditor-based StructureAPointHistory ObjectEditorReusing Point HistoryAPointHistoryUser Interface Code:Single Main ClassMore Modular ApproachEditor:AConsoleEditorEditor:ASwingPlotterEditorEditor:ABarChartEditorEditor:AnAWTPlotterEditorComposer:Single Main ClassAPointHistorySharing the ViewSharing the ControllerController Without ViewView Without ControllerMonolithic EditorAWT Plotter EditorAPointHistorySeparate View and ControllerController:AnAWTControllerView:ABarchartViewAPointHistoryaddElement( )size( )elementAt( )Performs Input Performs OutputWrite methodsRead methodsMultiple Views and ControllersAPointHistoryController:AConsoleControllerController:AnAWTControllerController:AnAWTControllerController:ASwingControllerView:AConsoleViewView:ABarChartViewView:APlotterViewView:APlotterViewSyncing Controllers and Views?Model View Controller FrameworkModel:APointHistoryModelController:AConsoleControllerController:AnAWTControllerController:AnAWTControllerController:ASwingControllerView:AConsoleViewView:ABarChartViewView:APlotterViewView:APlotterViewChanged object notifies viewsListenableListenersModel View Controller FrameworkModel:APointHistoryModelController:AConsoleControllerController:AnAWTControllerController:AnAWTControllerController:ASwingControllerView:AConsoleViewView:ABarChartViewView:APlotterViewView:APlotterViewComposer:Single Main ClassComposer connects models, views, controllersClass Vs InstanceModel:APointHistoryModelController:AConsoleControllerController:AnAWTControllerController:AnAWTControllerController:ASwingControllerView:AConsoleViewView:ABarChartViewView:APlotterViewView:APlotterViewComposer:Single Main ClassDifferent StateMVC FrameworkModel:APointHistoryModelInstanceController:AConsoleControllerinstanceController:AnAWTControllerinstanceController:AnAWTControllerinstanceController:ASwingControllerinstanceView:AConsoleViewinstanceView:ABarChartViewinstanceView:APlotterViewinstanceView:APlotterViewinstanceComposer:Single Main ClassModelModel:APointHistoryModel InstanceController:AConsoleControllerinstanceController:AnAWTControllerinstanceController:AnAWTControllerinstanceController:ASwingControllerinstanceView:AConsoleViewinstanceView:ABarChartViewinstanceView:APlotterViewinstanceView:APlotterViewinstanceComposer:Single Main ClassModel Vs PointHistoryAPointHistory InstanceController:AConsoleControllerinstanceController:AnAWTControllerinstanceController:AnAWTControllerinstanceController:ASwingControllerinstanceView:AConsoleViewinstanceView:ABarChartViewinstanceView:APlotterViewinstanceView:APlotterViewinstanceComposer:Single Main ClassReusing PointHistoryPointHistoryAPointHistoryIMPLEMENTSAPointHistoryModelEXTENDSPointModelEXTENDSIMPLEMENTSNotification SchemeModel:APointHistoryModel InstanceView:AConsoleViewinstanceView:ABarChartViewinstanceView:APlotterViewinstanceView:APlotterViewinstance• Each view is registered with model.• Each write method in model calls a notification method in each view.•Notification method updates display.Model:PointModel Instance (Animating Point)• Each student is registered with professor’s listserv.• When web page is updated mail sent to students.•Student reads web page.View with Multiple ModelsAPointHistoryModel InstancePointModel InstanceGeneral Notification SchemeModel:APointHistoryModel InstanceView:AConsoleViewinstanceView:ABarChartViewinstanceView:APlotterViewinstanceView:APlotterViewinstance•View may have multiple models with common notification method.•Notification method parameter indicates which model.Model:PointModel Instance (Animating Point)PointHistoryModel & PointHistoryListenerpublic interface PointHistoryModel extends PointHistory {public void addListener (PointHistoryListener pointHistoryListener);public void removeListener (PointHistoryListener pointHistoryListener);}public interface PointHistoryListener {public void pointHistoryUpdated(PointHistory pointHistory);}Called whenever model is updatedUpdated object (model)View (console, barchart, plotter ..)Common interface of all viewsAPointHistoryModelimport java.util.Vector;import java.util.Enumeration;public class APointHistoryModel extends APointHistory implements PointHistoryModel {public void addElement (int x, int y) {super.addElement(x, y);notifyListeners();}Vector listeners = new Vector();public void addListener (PointHistoryListener pointHistoryListener) {listeners.addElement(pointHistoryListener);}public void


View Full Document

UNC-Chapel Hill COMP 14 - Model View Controller Pattern

Download Model View Controller Pattern
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Model View Controller Pattern and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Model View Controller Pattern 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?