MVC and DCA: Two complimentary system architectures. Trygve Reenskaug Department of Informatics University of Oslo trygver@ifi.uio.no http://heim.ifi.uio.no/~trygver/2006/09-JavaZone/ MVC and DCA: JavaZone 2006 © Trygve Reenskaug 2006 2016.05.29 Slide 1 The BabyUML Project The essence of object orientation is that objects interact to accomplish some desired The pricefunctionality. of reliability is the pursuit of the utmost simplicity BabyUML Goal: (C.A.R. Hoare, 1980 Turing Award lecture) Answer explicitly – What are the objects? – How are they interlinked? – How do they interact? Do more – type less MVC and DCA: JavaZone 2006 © Trygve Reenskaug 2006 2016.05.29 Slide 3 Model – View - Controller mental model User computer data Model View View bridges gap between user Mental model and Computer data MVC and DCA: JavaZone 2006 © Trygve Reenskaug 2006 2016.05.29 Slide 4 Model – View - Controller mental model User Controller computer data * 1 View * * Model View View bridges gap between user Mental model and Controller creates and coordinates Computer data Run Demo multiple Views MVC and DCA: JavaZone 2006 © Trygve Reenskaug 2006 2016.05.29 Slide 5 MVC Demo http://heim.ifi.uio.no/~trygver/2006/09-JavaZone/babyExample4.html MVC and DCA: JavaZone 2006 © Trygve Reenskaug 2006 2016.05.29 Slide 6 The Anatomy of MVC Demo controller :Controller panelView :DependencyPanel :ActivityView http://heim.ifi.uio.no/~trygver/2006/09-JavaZone/babyExample4.html MVC and DCA: JavaZone 2006 © Trygve Reenskaug 2006 2016.05.29 Slide 7 MVC example Synchronized Selection focusView User pointAndClickMouse controller actionPerformed() activityView* selectionChanged() isSelected() present MVC and DCA: JavaZone 2006 © Trygve Reenskaug 2006 2016.05.29 Slide 8 MVC example Synchronized Selection class Controller { Activity selection; inputView controller leafView* User public void actionPerformed (ActionEvent e) { pointAndClickMouse ActivityView source = (ActivityView) e.getSource(); selection = source.activity(); actionPerformed() for (ActivityView view : activityViews) { selectionChanged() view.selectionChanged(); } isSelected() repaint(); } public boolean isSelected (Activity act) { present return ( selection == act ); } MVC and DCA: JavaZone 2006 © Trygve Reenskaug 2006 2016.05.29 Slide 9 Model – View - Controller controller MVC and DCA: JavaZone 2006 Model © Trygve Reenskaug 2006 2016.05.29 Slide 10 the Model as a single Object illustration copied from The Java Tutorial Copyright 1995-2005 Sun Microsystems, Inc. methods (behavior) derived attributes owned attributes (state) MVC and DCA: JavaZone 2006 © Trygve Reenskaug 2006 2016.05.29 Slide 11 the DCA Model Component Data + Collaboration + Algorithm Algorithms Collaborations Data netBase activities dependencies member Objects (behavior) MVC and DCA: JavaZone 2006 (derived attributes) (external data view) © Trygve Reenskaug 2006 2016.05.29 resource allocations (owned attributes) (base data) Slide 12 DCA netBase – UML schema Data Activity name earlyStart successor earlyFinish * DependencyPanel duration Dependency color netBase activities dependencies allocations GanttPanel resource * predecessor ResourcePanel MVC and DCA: JavaZone 2006 © Trygve Reenskaug 2006 2016.05.29 Slide 14 DCA netBase - Java public class Activity { private Integer earlyStart, earlyFinish, duration; private String name; private Color color = Color.gray; …. activities netBase public class BabyBase extends Observable implements Observer { private Set<Activity> activities; private Set<MemberDependency> dependencies; dependencies Java as schema language resource allocations public class MemberDependency { private Activity predecessor, successor; ... Data (state) MVC and DCA: JavaZone 2006 © Trygve Reenskaug 2006 2016.05.29 Slide 15 First DCA example DependencyPanel layout + collaboration activities dependencies DependencyPanel network Base layout Algorithm allocations (behavior) GanttPanel Collaboration (external data view) resource Base Data (state) ResourcePanel MVC and DCA: JavaZone 2006 © Trygve Reenskaug 2006 2016.05.29 Slide 17 DCA ex.1: DependencyPanel responsible for layout Algorithm layout Algorithm Model (behavior) private void addActivityViews() { activities // Compute gridX, gridY, x0, y0, buttonExtent for (int rank=0; rank <= rankedCollab.maxRank(); rank++) { // compute xPos, yPos for (Activity act : rankedCollab.activityListAtRank(rank)) { dependencies ActivityView actView = new ActivityView(controller, act, 24) ; DependencyPanel add (actView); yPos = yPos + gridY; network // misc. computations layout Algorithm GanttPanel Base (behavior) } } } allocations Collaboration (external data view) resource Base Data (state) ResourcePanel MVC and DCA: JavaZone 2006 © Trygve Reenskaug 2006 2016.05.29 Slide 18 DCA ex.1: RankedCollab Query Model define activityListAtRank(Integer rank) as select act from DependencyPanel activities act where rank(act) = rank dependencies (external data view) allocations resource rankedCollab GanttPanel netBase activities Data (state) ResourcePanel MVC and DCA: JavaZone 2006 © Trygve Reenskaug 2006 2016.05.29 Slide 20 DCA ex.1: RankedCollab Java Model public List<Activity> activityListAtRank (Integer rank) { List<Activity> activityListAtRank = new ArrayList<Activity>(); dependencies DependencyPanel for (Activity act : bBase. allActivities()) { if (rankOf(act)layout == rank) {Algorithm } GanttPanel return activityListAtRank ; } rankedCollab (external data view) allocations resource } activityListAtRank.add(act); (behavior) netBase activities Data (state) ResourcePanel MVC and DCA: JavaZone 2006 © Trygve Reenskaug 2006 2016.05.29 Slide 21 Second DCA example frontloading Model activities Algorithms (behavior) dependencies network Base allocations Collaborations (external data views) resource Base Data (state) MVC and DCA: JavaZone 2006 © Trygve Reenskaug 2006 2016.05.29 Slide 22 D CA ex.2: frontloading query - frontloader Model activities Algorithms DependencyPanell define frontloader as (behavior) dependencies network (select act Base from Activities act allocations where act.earlyStart == null GanttPane and (for all pred in predecessors(act): Collaborations l pred.earlyStart != null) resource (external data views) Base ) someInstance BabyDataBase (state) ResourcePane l MVC and DCA: JavaZone 2006 © Trygve Reenskaug 2006 2016.05.29 Slide 23 D CA ex.2: frontloading Java - frontloader Model activities public Activity frontloader() { for (Activity act : netBase.allActivities())A { lgorithms if (act.earlyStart() == null) { (behavior) dependencies Set<Activity> predSet = predecessorsOf(act); DependencyPanell private boolean areAllDone(Set<Activity> actSet) { if (areAllDone(predSet)) { network boolean allPredsDone = true; frontloader = act; Base for ( Activity pred : actSet) { return (frontloader); allocations } if (pred.earlyStart() == null) { GanttPane } allPredsDone = false; Collaborations } l break; resource (external data views) return }null; Base } } BabyDataBase (state) return allPredsDone; } ResourcePane l MVC and DCA: JavaZone 2006 © Trygve Reenskaug 2006 2016.05.29 Slide 24 DCA ex.2: frontloading frontload algorithm - Java Model activities public void frontload (Integer startWeek) { // reset all for (Activity act : frontloadCollab.resetters()) { act.setEarlyStart (null); } DependencyPanell Algorithms (behavior) dependencies // frontload all network Activity frontloader; Base while ((frontloader = frontloadCollab.frontloader()) != null) { allocations Integer earlyStart = startWeek; for (Activity pred : frontloadCollab.frontPredecessors()) { GanttPane ollaborations earlyStart = l Math.max(earlyStart, pred.earlyFinish() + 1);(external data views) resource Base } frontloader.setEarlyStart(earlyStart); Baby ataBase } (state) } C D ResourcePane l MVC and DCA: JavaZone 2006 © Trygve Reenskaug 2006 2016.05.29 Slide 26 Second DCA example compute earlyFinish Model activities Algorithms (behavior) dependencies public Integer earlyFinish() { if (earlyStart != null) { network Base return (earlyStart + duration – 1); allocations } else { Collaborations return null; resource (external data views) } Base Data } (state) MVC and DCA: JavaZone 2006 © Trygve Reenskaug 2006 2016.05.29 Slide 27 MVC – DCA Critique • MVC – separate Model and View • when GUI and Model are deployed on different machine. • when the application code is complex. – write several View classes for the same Model class • when the user needs to see the Model from several perspectives. – write a Controller class to create and coordinate the Views • when the user needs to see them simultaneously. • DCA – simplify Data with a baby database • when the data structure is complex. – separate out data queries in Collaboration classes • if Algorithms need to see data from different perspectives. – create a separate Algorithm class • if the Algorithm spans several member objects. MVC and DCA: JavaZone 2006 © Trygve Reenskaug 2006 2016.05.29 Slide 28 The BabyUML Project Status The essence of object orientation is that objects interact to accomplish some desired The pricefunctionality. of reliability is the pursuit of the utmost simplicity BabyUML Goal: (C.A.R. Hoare, 1980 Turing Award lecture) Answer explicitly What are the objects? Database definition How are they interlinked? Collaboration How do they interact? Algorithm Do more – type less Remains to be done MVC and DCA: JavaZone 2006 © Trygve Reenskaug 2006 2016.05.29 Slide 29 More reading http://www.ifi.uio.no/~trygver mailto: trygver ‘at’ ifi.uio.no dca-demo example code: http://heim.ifi.uio.no/~trygver/2006/09-JavaZone/BabyProject-2/ Trygve Reenskaug: Original MVC notes from Xerox PARC http://heim.ifi.uio.no/~trygver/1979/mvc-1/1979-05-MVC.pdf http://heim.ifi.uio.no/~trygver/1979/mvc-2/1979-12-MVC.pdf Charles Antony Richard Hoare: The Emperor's Old Clothes. 1980 Turing Award lecture. Comm.ACM 24, 2 (Feb. 1981) Trygve Reenskaug: The BabyUML discipline of programming (where A Program = Data + Communication + Algorithms). SoSym 5,1 (April 2006). DOI: 10.1007/s10270-006-0008-x. http://heim.ifi.uio.no/~trygver/2006/SoSyM/trygveDiscipline.pdf Unified Modeling Language: Superstructure. Version 2.1. Object Management Group (OMG) document ptc/06-04-02. http://www.omg.org Cattell, Barry: The Object Data Standard: ODMG 3.0. Academic Press, London, 2000. ISBN 1-55860-647-4 Erik Arisholm and Dag Sjøberg: A Controlled Experiment with Professionals to Evaluate the Effect of a Delegated versus Centralized Control …, Simula Research Laboratory Technical Report 2003-6 http://www.simula.no/publication_one.php?publication_id=601 Reenskaug, Wold, Lehne: Working With Objects. This book is out of print. A .pdf version kan be downloaded free from http://www.ifi.uio.no/~trygver Donald A. Norman: The Design of Everyday Things. Doubleday/Currency 1990. ISBN 0-385-26774-6 MVC and DCA: JavaZone 2006 © Trygve Reenskaug 2006 2016.05.29 Slide 30