MVC and DCA Two complimentary system architectures Trygve





























- Slides: 29
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 -Java. Zone/ MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006
Legal Notice This presentation is copyright © 2006 Trygve Reenskaug Oslo, Norway. All rights reserved. Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that the copies are not made for profit or commercial advantage and that copies bear this notice and full citation on the first page. MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006
The Baby. UML Project Baby. UML slogan: The price of reliability is the pursuit of the utmost simplicity (C. A. R. Hoare, 1980 Turing Award lecture) Baby. UML goal: High level programming disciplines. e. g. : Model - View - Controller Data - Collaboration - Algorithm MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 19. 02. 2021 3
Model – View - Controller mental model User computer information View Model View bridges gap between user Mental model and Computer information MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006
Model – View - Controller mental model User Controller 1 * * computer information * Model View Controller creates and coordinates multiple Views Run Demo MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006
MVC Demo http: //heim. ifi. uio. no/~trygver/2006/09 -Java. Zone/baby. Example 4. html MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 19. 02. 2021 6
The Anatomy of MVC Demo controller : Controller : Activity. View MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 panel. View : Dependency. Panel 19. 02. 2021 7
MVC example Synchronized Selection input. View User point. And. Click. Mouse controller action. Performed() activity. View* selection. Changed() is. Selected() present MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 19. 02. 2021 8
MVC example Synchronized Selection class Controller { Activity selection; input. View controller leaf. View* User public void action. Performed(Action. Event e) { point. And. Click. Mouse Activity. View source = (Activity. View)e. get. Source(); selection = source. activity(); action. Performed() for (Activity. View view : activity. Views) { view. selection. Changed(); selection. Changed() } is. Selected() repaint(); } public boolean is. Selected(Activity act) { present return ( selection == act ); } MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 19. 02. 2021 9
Model – View - Controller controller MVC and DCA: Java. Zone 2006 Model © Trygve Reenskaug 2006 19. 02. 2021 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: Java. Zone 2006 © Trygve Reenskaug 2006 19. 02. 2021 11
the DCA Component Data + Collaboration + Algorithm DCA Component Algorithms Data activities Collaborations dependencies member. Object (behavior) MVC and DCA: Java. Zone 2006 (derived attributes) © Trygve Reenskaug 2006 (owned attributes) 19. 02. 2021 12
the Model as a DCA Component Data DCA Component Algorithms frontload Collaborations activities frontload. Collab dependencies ranked. Collab network Base allocations (behavior) MVC and DCA: Java. Zone 2006 (derived attributes) © Trygve Reenskaug 2006 (owned attributes) 19. 02. 2021 13
MVC -- DCA the structure Model activities Collaborations net. Base Algorithm Data dependencies Dependency. Panel Gantt. Panel resource allocations Resource. Panel MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 19. 02. 2021 14
DCA baby database – UML schema Model Data net. Base Collaborations activities Activity name early. Start successor Algorithms early. Finish * duration dependencies Dependency. Panel Dependency color allocations Gantt. Panel UML as schema language resource * predecessor Resource. Panel MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 19. 02. 2021 15
DCA baby database - Java Model public class Activity { private Integer early. Start, early. Finish, duration; Dependency. Panel private String name; private Color color = Color. gray; …. activities dependencies Java as schema language resource allocations public class Member. Dependency { Gantt. Panel private Activity predecessor, successor; . . . net. Base public class Baby. Base extends Observable implements Observer { private Set<Activity> activities; private Set<Member. Dependency> dependencies; Data (state) Resource. Panel MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 19. 02. 2021 16
DCA ex. 1: Dependency. Panel is responsible for layout algorithm Model activities dependencies layout Algorithm (behavior) network Base allocations Gantt. Pane l Collaboration (exernal view) resource Base Data (state) Resource. Pane l MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 19. 02. 2021 17
DCA ex. 1: Dependency. Panel responsible for layout Algorithm Model activities Activities private void add. Activity. Views() { // Compute grid. X, grid. Y, x 0, y 0, button. Extent for (int rank=0; rank <= ranked. Collab. max. Rank(); rank++) { // compute x. Pos, y. Pos for (Activity act : ranked. Collab. activity. List. At. Rank(rank)) { Activity. View act. View = new Activity. View(controller, act, 24) ; dependencies Dependencies add(act. View); Dependency. Panel y. Pos = y. Pos + grid. Y; // misc. computations network Base } Resource allocations Allocations } Gantt. Pane l } resource Base Collaborations Resource. Pane l MVC and DCA: Java. Zone 2006 (exernal views) © Trygve Reenskaug 2006 19. 02. 2021 18
DCA ex. 1: Collaboration Ranked. Collab is a Data projection Model net. Base activities Ranked. Collab dependencies Dependency. Panel layout Algorithm (behavior) Gantt. Pane l Collaboration (exernal view) resource allocations Data (state) Resource. Pane l MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 19. 02. 2021 19
DCA ex. 1: Ranked. Collab query Model activities Ranked. Collab define activity. List. At. Rank(Integer rank) as select act Dependency. Panel from activities act where rank(act) = rank dependencies network Base allocations Gantt. Pane l Collaborations (exernal views) Resource. Pane l MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 19. 02. 2021 resource Base 20
DCA ex. 1: Ranked. Collab Java Model activities Ranked. Collab public List<Activity> activity. List. At. Rank(Integer rank) { List<Activity> activity. List. At. Rank define activity. List. At. Rank(Integer rank) as = new Array. List<Activity>(); act for select (Activity act : b. Base. all. Activities()) { Dependency. Panel from activities act if (rank. Of(act) == rank) { where rank(act) = rank activity. List. At. Rank. add(act); } } Gantt. Pane return activity. List. At. Rank ; l } dependencies network Base allocations Collaborations (exernal views) resource Base Resource. Panel MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 19. 02. 2021 21
Data – Collaboration – Algorithm DCA ex. 2: frontloading Model activities Algorithms (behavior) dependencies network Base allocations Gantt. Pane l Collaborations resource Base Baby. Data. Base (exernal views) (state) Resource. Pane l MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 19. 02. 2021 22
DCA ex. 2: frontloading frontload algorithm - Java Model activities public void frontload(Integer start. Week) { // reset all lgorithms for (Activity act : frontload. Collab. resetters()) { (behavior) act. set. Early. Start (null); dependencies Dependency. Panell } // frontload all network Activity frontloader; Base while ((frontloader = frontload. Collab. frontloader()) != null) { allocations Integer early. Start = start. Week; for(Activity pred : frontload. Collab. front. Predecessors()) { Gantt. Pane ollaborations early. Start = l Math. max(early. Start, pred. early. Finish() + 1); (exernal views) resource } Base frontloader. set. Early. Start(early. Start); Baby ata. Base } (state) } A C D Resource. Pane l MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 19. 02. 2021 23
CA ex. 2: frontloading D query - frontloader Model activities Algorithms define frontloader() as (behavior) dependencies (select. Dependency. Panell act from Activities act network Base where act. early. Start == null allocations and (for all pred in predecessors(act): Gantt. Pane Collaborations pred. early. Start != null) l resource (exernal views) ) some. Instance Base Baby. Data. Base (state) Resource. Pane l MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 19. 02. 2021 24
CA ex. 2: frontloading D Java - frontloader Model activities public Activity frontloader() { for (Activity act : net. Base. all. Activities()) { lgorithms if (act. early. Start() == null) { (behavior) Set<Activity> pred. Set = predecessors. Of(act); dependencies Dependency. Panell if (are. All. Done(pred. Set)) { frontloader = act; network return(frontloader); private boolean are. All. Done(Set<Activity> act. Set) { Base } boolean all. Preds. Done = true; allocations } for ( Activity pred : act. Set) { } Gantt. Pane if (pred. early. Start() == null) { ollaborations return null; all. Preds. Done = false; l } resource (exernal views) break; Base } Baby ata. Base } (state) return all. Preds. Done; Resource. Pane } A C D l MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 19. 02. 2021 25
CA ex. 2: frontloading D Java – are. All. Done? Model activities public Activity frontloader() { for (Activity act : net. Base. all. Activities()) { lgorithms if (act. early. Start() == null) { (behavior) Set<Activity> pred. Set = predecessors. Of(act); dependencies Dependency. Panell if (are. All. Done(pred. Set)) { frontloader = act; network return(frontloader); private boolean are. All. Done(Set<Activity> act. Set) { Base } boolean all. Preds. Done = true; allocations } for ( Activity pred : act. Set) { } Gantt. Pane if (pred. early. Start() == null) { ollaborations return null; all. Preds. Done = false; l } resource (exernal views) break; Base } Baby ata. Base } (state) return all. Preds. Done; Resource. Pane } A C D l MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 19. 02. 2021 26
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 objects. MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 19. 02. 2021 27
MVC – DCA Conclusion v. Your left brain works up to the whole step by step, focusing on details; makes logical deductions; verbal üuse it to create and understand algorithms v. Your right brain sees the whole first, then the details; makes lateral connections; pictorial üuse it to create and understand data models and collaborations CDA facilitates simplicity because it separates concern and lets you use your whole brain MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 19. 02. 2021 28
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 -Java. Zone/Baby. Project-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 Baby. UML discipline of programming (where A Program = Data + Communication + Algorithms). So. Sym 5, 1 (April 2006). DOI: 10. 1007/s 10270 -006 -0008 -x. http: //heim. ifi. uio. no/~trygver/2006/So. Sy. M/trygve. Discipline. 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: Java. Zone 2006 © Trygve Reenskaug 2006





























