Unformatted text preview:

Model View ControllerModel View Controller PatternUser Interface ObjectsCounterConsole Input and OutputConsole Input and JOption OutputConsole Input,Output and JOption OutputImplementation ConstraintPattern-free ImplementationSlide 10Model/Interactor SeparationComposing Model and InteractorCounter ModelConsole InteractorMixed InteractorMultiple InteractorDrawbacks of Monolithic UIModel/Interactor PatternMVC PatternMVC Pattern in CounterMultiple Views and ControllersSyncing Controllers & ViewObserver/Observable PatternSlide 24Observer with multiple ObservablesNotification SchemeGeneral Notification SchemeSlide 28Implementation dependent issuesModel, View and Controller (MVC)Counter Observable and Observer?Counter Observable and ObserverSlide 33Console ViewSlide 35JOption ViewConsole Controller InterfaceConsole ControllerConsole MainConsole and JOption MainSlide 41Mixed UI MainFaçade PatternFacade patternFaçade: Compose objects into a single unit exposing methods relevant to that unitInteractor FacadeConsoleControllerAndView FacadeConsole Controller And JOption View MainConsole View + ControllerConsole Controller + JOptionView(Console Controller + View) + JOption ViewFacade over facadeMain with two views and OEObservers that are not viewsRocket ObserverInstances created and composedRocket InterfaceRocket Launching FacadeSlide 59Rocket launching mainSlide 61Basic NotificationSlide 63Implicit ObserverNotification with Change DescriptionJava Observable and ObserverNotification with Changed ValueNotification with ChangeNotification with New and Old ValueNotification with Single Event ObjectJava TextField and ActionListenerSlide 72Observing multiple attributesMultiple update methodsSingle update methodProperty ChangesSlide 77Multiple Observer/Observable InterfacesModel View ControllerPrasun DewanComp 114Model View Controller Pattern•Issue–How to create user-interface objects like object editor•Model-View-Controller Pattern–Observer sub-patternUser Interface Objects•How to reuse code among different user interfaces?•How to simultaneously create multiple user interfaces to same object?–Different views for same user.•Slide sorter vs. Outline–How to create same or different view for each user sharing an object•Distributed presentationCounter•Can add arbitrary positive/negative value to an integer.•Different user interfaces.Console Input and OutputConsole Input and JOption OutputConsole Input,Output and JOption OutputImplementation Constraint•Re-use as much code as possible in the three implementationsPattern-free Implementationpublic class ConsoleUI { static int counter = 0; public static void main(String[] args) {while (true) { int nextInput = readInt(); if (nextInput == 0) return; counter += nextInput; System.out.println("Counter: " + counter);} }}Pattern-free Implementationpublic class ConsoleUI { static int counter = 0; public static void main(String[] args) {while (true) { int nextInput = readInt(); if (nextInput == 0) return; counter += nextInput; JOptionPane.showMessageDialog(null, "Counter: " + counterValue);} }}Counter code duplicatedModel/Interactor SeparationAConsoleUIAMixedUICounterAMultipleUIModelModel has no UI code and only semantics!InteractorInteractorInteractorComposing Model and Interactorpublic static main (String args[]) (new AConsoleUI()).edit (new ACounter());}Counter Modelpackage models;public class ACounter implements Counter {int counter = 0;public void add (int amount) {counter += amount;}public int getValue() {return counter;}}• Code reusability• Less duplication• Fewer changesConsole Interactorpackage interactors;public class AConsoleUI implements ConsoleUI { public void edit (Counter counter) {while (true) { int nextInput = readInt(); if (nextInput == 0) return; counter.add(nextInput); System.out.println("Counter: " + counter.getValue());} }}Shared model codeInputOutputMixed Interactorpackage interactors;public class AConsoleUI implements ConsoleUI { public void edit (Counter counter) {while (true) { int nextInput = readInt(); if (nextInput == 0) return; counter.add(nextInput); JOptionPane.showMessageDialog(null, "Counter: " + counter.getValue());} }}Shared model codeInputOutputMultiple Interactorpackage interactors;public class AConsoleUI implements ConsoleUI { public void edit (Counter counter) {while (true) { int nextInput = readInt(); if (nextInput == 0) return; counter.add(nextInput); System.out.println("Counter: " + counter.getValue()); JOptionPane.showMessageDialog(null, "Counter: " + counter.getValue());} }}Shared model codeInputOutputDrawbacks of Monolithic UIAConsoleUIAMixedUIAMultipleUIACounterDuplicated input codeDuplicated output codeModel/Interactor PatternInteractorModelArbitrary UI unaware methodsComputation codeUI CodeMVC PatternController ViewModelPerforms InputPerforms OutputWrite methodsRead methodsController ViewMVC Pattern in CounterModeladd()getValue()Performs InputPerforms OutputMultiple Views and ControllersModelController 1Controller 2Controller 3Controller MView 1View 2View 3View NSyncing Controllers & ViewModelController 1Controller 2Controller 3Controller MView 1View 2View 3View NObserver/Observable PatternModelChanged object notifies viewsObservableObserverController 1Controller 2Controller 3Controller MView 1View 2View 3View NObserver/Observable PatternObservable 1Observer 1Observer 2Observer 3Observer NObservable 2Observer with multiple Observables•A single battle simulation view observing–Multiple planes–Multiple tanksNotification SchemeObservable 1• Each observer is registered with observable.• Each write method in observable calls a notification method in each observer.•Notification method in observer reads model .Observable 2• Each student is registered with professor’s listserv.• When web page is updated mail sent to students.•Student reads web page.Observer 1Observer 2Observer 3Observer NGeneral Notification Scheme•Observers may have multiple observerables with common notification method.•Notification method parameter indicates which observable.Observable 1Observable 2Observer 1Observer 2Observer 3Observer NMVC PatternController ViewModelPerforms InputPerforms OutputWrite methodsRead methodsNotification methodImplementation dependent issues•How does controller know about model?–Model connection method invoked on it.–By model or some other


View Full Document

UNC-Chapel Hill COMP 114 - Model View Controller

Download Model View Controller
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 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 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?