MVC and DCA Two complimentary system architectures Trygve

  • Slides: 26
Download presentation
MVC and DCA: Two complimentary system architectures. Trygve Reenskaug Department of Informatics University of

MVC and DCA: Two complimentary system architectures. Trygve Reenskaug Department of Informatics University of Oslo Java code at http: //heim. ifi. uio. no/~trygver/2006/09 -Java. Zone/ MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006

The Baby. UML Project The essence of object orientation is that objects interact to

The Baby. UML 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 Baby. UML 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: Java. Zone 2006 © Trygve Reenskaug 2006 15. 09. 2020 3

Model – View - Controller computer data mental model Model View User View bridges

Model – View - Controller computer data mental model Model View User View bridges gap between user Mental model and Computer data MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 15. 09. 2020 4

Model – View - Controller mental model Controller 1 View User computer data *

Model – View - Controller mental model Controller 1 View User computer data * * * Model View bridges gap between user Mental model and Controller creates and coordinates Computer data Run Demo multiple Views MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 15. 09. 2020 5

MVC Demo http: //heim. ifi. uio. no/~trygver/2006/09 -Java. Zone/baby. Example 4. html MVC and

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 15. 09. 2020 6

The Anatomy of MVC Demo controller : Controller panel. View : Dependency. Panel :

The Anatomy of MVC Demo controller : Controller panel. View : Dependency. Panel : Activity. View http: //heim. ifi. uio. no/~trygver/2006/09 -Java. Zone/baby. Example 4. html MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 15. 09. 2020 7

MVC example Synchronized Selection User focus. View controller activity. View* point. And. Click. Mouse

MVC example Synchronized Selection User focus. View controller activity. View* point. And. Click. Mouse action. Performed() selection. Changed() is. Selected() present MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 15. 09. 2020 8

MVC example Synchronized Selection User class Controller { Activity selection; input. View controller leaf.

MVC example Synchronized Selection User class Controller { Activity selection; input. View controller leaf. View* 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 15. 09. 2020 9

Model – View - Controller controller MVC and DCA: Java. Zone 2006 Model ©

Model – View - Controller controller MVC and DCA: Java. Zone 2006 Model © Trygve Reenskaug 2006 15. 09. 2020 10

the Model as a single Object illustration copied from The Java Tutorial Copyright 1995

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 15. 09. 2020 11

the DCA Model Component Data + Collaboration + Algorithms Collaborations Data net. Base activities

the DCA Model Component Data + Collaboration + Algorithms Collaborations Data net. Base activities dependencies member Objects (behavior) MVC and DCA: Java. Zone 2006 (derived attributes) (external data view) © Trygve Reenskaug 2006 15. 09. 2020 resource allocations (owned attributes) (base data) 12

DCA net. Base – UML schema Data Activity name early. Start successor early. Finish

DCA net. Base – UML schema Data Activity name early. Start successor early. Finish * Dependency. Panel duration Dependency color net. Base activities dependencies allocations Gantt. Panel resource * predecessor Resource. Panel MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 15. 09. 2020 14

DCA net. Base - Java public class Activity { private Integer early. Start, early.

DCA net. Base - Java public class Activity { private Integer early. Start, early. Finish, duration; private String name; private Color color = Color. gray; …. activities net. Base public class Baby. Base extends Observable implements Observer { private Set<Activity> activities; private Set<Member. Dependency> dependencies; dependencies Java as schema language resource allocations public class Member. Dependency { private Activity predecessor, successor; . . . Data (state) MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 15. 09. 2020 15

First DCA example Dependency. Panel layout + collaboration activities dependencies Dependency. Panel network Base

First DCA example Dependency. Panel layout + collaboration activities dependencies Dependency. Panel network Base layout Algorithm (behavior) allocations Gantt. Panel Collaboration (external data view) resource Base Data (state) Resource. Panel MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 15. 09. 2020 17

DCA ex. 1: Dependency. Panel responsible for layout Algorithm Model (behavior) private void add.

DCA ex. 1: Dependency. Panel responsible for layout Algorithm Model (behavior) private void add. Activity. Views() { activities // 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 Dependency. Panel add (act. View); y. Pos = y. Pos + grid. Y; network // misc. computations layout Algorithm Gantt. Panel (behavior)} } } Base allocations Collaboration (external data view) resource Base Data (state) Resource. Panel MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 15. 09. 2020 18

DCA ex. 1: Ranked. Collab Query Model define activity. List. At. Rank(Integer rank) as

DCA ex. 1: Ranked. Collab Query Model define activity. List. At. Rank(Integer rank) as select act from. Dependency. Panel activities act where rank(act) = rank dependencies (external data view) allocations resource ranked. Collab Gantt. Panel net. Base activities Data (state) Resource. Panel MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 15. 09. 2020 20

DCA ex. 1: Ranked. Collab Java Model public List<Activity> activity. List. At. Rank (Integer

DCA ex. 1: Ranked. Collab Java Model public List<Activity> activity. List. At. Rank (Integer rank) { List<Activity> activity. List. At. Rank = new Array. List<Activity>(); Dependency. Panel for (Activity act : b. Base. all. Activities()) { if (rank. Of(act)layout == rank) {Algorithm } Gantt. Panel return activity. List. At. Rank ; } dependencies ranked. Collab (external data view) allocations resource } activity. List. At. Rank. add(act); (behavior) net. Base activities Data (state) Resource. Panel MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 15. 09. 2020 21

Second DCA example frontloading Model activities t r a St y Algorithmsing h l

Second DCA example frontloading Model activities t r a St y Algorithmsing h l s r i a n d i e a F (behavior) e o y t l dependencies l t u r n a p o e r m f e o t C u or network f p y m t Base i o v C ti c allocations a fy i t n Collaborations e d I resource (external data views) Base Data (state) MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 15. 09. 2020 22

CA ex. 2: frontloading D query - frontloader Model activities Algorithms Dependency. Panell define

CA ex. 2: frontloading D query - frontloader Model activities Algorithms Dependency. Panell define frontloader as (behavior) dependencies network (select act Base from Activities act allocations where act. early. Start == null Gantt. Pane and (for all pred in predecessors(act): ollaborations l pred. early. Start != null) resource (external data views) Base ) some. Instance C Baby. Data. Base (state) Resource. Pane l MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 15. 09. 2020 23

CA ex. 2: frontloading D Java - frontloader Model activities public Activity frontloader() {

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) dependencies Set<Activity> pred. Set = predecessors. Of(act); Dependency. Panell private boolean are. All. Done(Set<Activity> act. Set) { if (are. All. Done(pred. Set)) { network boolean all. Preds. Done = true; frontloader = act; Base for ( Activity pred : act. Set) { return (frontloader); allocations } if (pred. early. Start() == null) { Gantt. Pane } all. Preds. Done = false; ollaborations } l break; resource (external data views) return }null; Base } } Baby ata. Base return all. Preds. Done; (state) } Resource. Pane A C D l MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 15. 09. 2020 24

DCA ex. 2: frontloading frontload algorithm - Java Model activities public void frontload (Integer

DCA ex. 2: frontloading frontload algorithm - Java Model activities public void frontload (Integer start. Week) { Activity frontloader; lgorithms while ((frontloader = frontload. Collab. frontloader()) != null) { (behavior) dependencies Integer early. Start = start. Week; Dependency. Panell for (Activity pred : frontload. Collab. front. Predecessors()) { early. Start = network Math. max(early. Start, pred. early. Finish() + 1); Base } allocations frontloader. set. Early. Start(early. Start); Gantt. Pane } ollaborations } A l C resource Base Baby. Data. Base (external data views) (state) Resource. Pane l MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 15. 09. 2020 26

Second DCA example compute early. Finish Model activities Algorithms (behavior) dependencies public Integer early.

Second DCA example compute early. Finish Model activities Algorithms (behavior) dependencies public Integer early. Finish() { if (early. Start != null) { network Base return (early. Start + duration – 1); allocations } else { Collaborations return null; resource (external data views) } Base Data } (state) MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 15. 09. 2020 27

MVC – DCA Critique • MVC – separate Model and View • when GUI

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 not obvious from the code. – 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: Java. Zone 2006 © Trygve Reenskaug 2006 15. 09. 2020 28

The Baby. UML Project Status The essence of object orientation is that objects interact

The Baby. UML 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 Baby. UML Goal: (C. A. R. Hoare, 1980 Turing Award lecture) ØAnswer explicitly ü What are the objects? Database schema ü How are they interlinked? Collaboration ü How do they interact? Algorithm ØDo more – type less Remains to be done MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 15. 09. 2020 29

That’s all, thank you Questions? Java code and comments at http: //heim. ifi. uio.

That’s all, thank you Questions? Java code and comments at http: //heim. ifi. uio. no/~trygver/2006/09 -Java. Zone/ MVC and DCA: Java. Zone 2006 © Trygve Reenskaug 2006 15. 09. 2020 30

More reading http: //www. ifi. uio. no/~trygver mailto: trygver ‘at’ ifi. uio. no dca-demo

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