MVC and DCA: wo complimentary system architectures. Trygve Reenskaug

advertisement
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
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: JavaZone 2006
© Trygve Reenskaug 2006
2016.05.29
Slide 2
The BabyUML Project
BabyUML slogan:
The price of reliability is the pursuit of
the utmost simplicity
(C.A.R. Hoare, 1980 Turing Award lecture)
BabyUML goal:
High level programming disciplines.
e.g.: Model
- View - Controller
Data - Collaboration - Algorithm
MVC and DCA: JavaZone 2006
© Trygve Reenskaug 2006
2016.05.29
Slide 3
Model – View - Controller
mental
model
User
computer
information
Model
View
View bridges gap between
user Mental model and
Computer information
MVC and DCA: JavaZone 2006
© Trygve Reenskaug 2006
2016.05.29
Slide 4
Model – View - Controller
mental
model
User
Controller
*
computer
information
1
*
*
Model
View
Controller creates and coordinates
multiple Views
Run Demo
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
:ActivityView
MVC and DCA: JavaZone 2006
© Trygve Reenskaug 2006
panelView
:DependencyPanel
2016.05.29
Slide 7
MVC
example
Synchronized Selection
inputView
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 Component
Data + Collaboration + Algorithm
DCA Component
Algorithms
Data
activities
Collaborations
dependencies
memberObject
(behavior)
MVC and DCA: JavaZone 2006
(derived attributes)
© Trygve Reenskaug 2006
(owned attributes)
2016.05.29
Slide 12
the Model
as a DCA Component
Data
DCA Component
Algorithms
frontload
Collaborations
activities
frontloadCollab
dependencies
rankedCollab
network
Base
allocations
(behavior)
MVC and DCA: JavaZone 2006
(derived attributes)
© Trygve Reenskaug 2006
(owned attributes)
2016.05.29
Slide 13
MVC -- DCA
the structure
Model
activities
Collaborations
netBase
Algorithm
Data
dependencies
DependencyPanel
GanttPanel
resource
allocations
ResourcePanel
MVC and DCA: JavaZone 2006
© Trygve Reenskaug 2006
2016.05.29
Slide 14
DCA
baby database – UML schema
Model
Data
netBase
Collaborations activities
Activity
name
earlyStart
successor Algorithms
earlyFinish
*
duration
dependencies
DependencyPanel
Dependency
color
allocations
GanttPanel
UML as schema language
resource
*
predecessor
ResourcePanel
MVC and DCA: JavaZone 2006
© Trygve Reenskaug 2006
2016.05.29
Slide 15
DCA
baby database - Java
Model
public class Activity {
private
Integer earlyStart, earlyFinish, duration;
DependencyPanel
private String name;
private Color color = Color.gray; ….
activities
dependencies
Java as schema language
resource
allocations
public class MemberDependency {
GanttPanel
private Activity predecessor, successor; ...
netBase
public class BabyBase extends Observable implements Observer {
private Set<Activity> activities;
private Set<MemberDependency> dependencies;
Data
(state)
ResourcePanel
MVC and DCA: JavaZone 2006
© Trygve Reenskaug 2006
2016.05.29
Slide 16
DCA ex.1:
DependencyPanel
is responsible for layout algorithm
Model
activities
dependencies
layout Algorithm
(behavior)
network
Base
allocations
GanttPane
l
Collaboration
(exernal view)
resource
Base
Data
(state)
ResourcePane
l
MVC and DCA: JavaZone 2006
© Trygve Reenskaug 2006
2016.05.29
Slide 17
DCA ex.1:
DependencyPanel
responsible for layout Algorithm
Model
activities
Activities
private void addActivityViews() {
// Compute gridX, gridY, x0, y0, buttonExtent
for (int rank=0; rank <= rankedCollab.maxRank(); rank++) {
// compute xPos, yPos
for (Activity act : rankedCollab.activityListAtRank(rank)) {
ActivityView actView = new ActivityView(controller, act, 24) ;
dependencies
Dependencies
add(actView);
DependencyPanel
yPos = yPos + gridY;
// misc. computations
network
Base
}
Resource
allocations
Allocations
}
}
GanttPane
l
resource
Base
Collaborations
ResourcePane
l
MVC and DCA: JavaZone 2006
(exernal views)
© Trygve Reenskaug 2006
2016.05.29
Slide 18
DCA ex.1: Collaboration
RankedCollab is a Data projection
Model
netBase
activities
RankedCollab
dependencies
DependencyPanel
layout Algorithm
(behavior)
GanttPane
l
Collaboration
(exernal view)
resource
allocations
Data
(state)
ResourcePane
l
MVC and DCA: JavaZone 2006
© Trygve Reenskaug 2006
2016.05.29
Slide 19
DCA ex.1:
RankedCollab
query
Model
activities
RankedCollab
define activityListAtRank(Integer rank) as
select act
DependencyPanel
from activities act
where rank(act) = rank
dependencies
network
Base
allocations
GanttPane
l
Collaborations
(exernal views)
ResourcePane
l
MVC and DCA: JavaZone 2006
© Trygve Reenskaug 2006
2016.05.29
resource
Base
Slide 20
DCA ex.1:
RankedCollab
Java
Model
activities
RankedCollab
public List<Activity>
activityListAtRank(Integer rank) {
List<Activity> activityListAtRank
define activityListAtRank(Integer
rank) as
= new ArrayList<Activity>();
act
for select
(Activity
act : bBase. allActivities()) {
DependencyPanel
from activities act
if (rankOf(act) == rank) {
where rank(act) = rank
activityListAtRank .add(act);
}
}
GanttPane
return activityListAtRank ;
l
}
dependencies
network
Base
allocations
Collaborations
(exernal views)
resource
Base
ResourcePanel
MVC and DCA: JavaZone 2006
© Trygve Reenskaug 2006
2016.05.29
Slide 21
Data – Collaboration – Algorithm
DCA ex.2: frontloading
Model
activities
Algorithms
(behavior)
dependencies
network
Base
allocations
GanttPane
l
Collaborations
resource
Base
BabyDataBase
(exernal views)
(state)
ResourcePane
l
MVC and DCA: JavaZone 2006
© Trygve Reenskaug 2006
2016.05.29
Slide 22
DCA ex.2: frontloading
frontload algorithm - Java
Model
activities
public void frontload(Integer startWeek) {
// reset all
lgorithms
for (Activity act : frontloadCollab.resetters()) {
(behavior)
dependencies
act.setEarlyStart (null);
DependencyPanell
}
// 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); (exernal views)
resource
}
Base
frontloader.setEarlyStart(earlyStart);
Baby ataBase
}
(state)
}
A
C
D
ResourcePane
l
MVC and DCA: JavaZone 2006
© Trygve Reenskaug 2006
2016.05.29
Slide 23
D
CA ex.2: frontloading
query - frontloader
Model
activities
Algorithms
define frontloader() as
(behavior)
dependencies
(selectDependencyPanell
act
network
from Activities act
Base
where act.earlyStart == null
allocations
and (for all pred in predecessors(act):
GanttPane
Collaborations
pred.earlyStart
!=
null)
l
resource
(exernal views)
) someInstance
Base
BabyDataBase
(state)
ResourcePane
l
MVC and DCA: JavaZone 2006
© Trygve Reenskaug 2006
2016.05.29
Slide 24
D
CA ex.2: frontloading
Java - frontloader
Model
activities
public Activity frontloader() {
for (Activity act : netBase.allActivities()) {
lgorithms
if (act.earlyStart() == null) {
(behavior)
Set<Activity> predSet = predecessorsOf(act);
dependencies
DependencyPanell
if (areAllDone(predSet)) {
frontloader = act;
network
return(frontloader);
private boolean areAllDone(Set<Activity> actSet) {
Base
}
boolean allPredsDone = true;
allocations
}
for ( Activity pred : actSet) {
}
GanttPane
if (pred.earlyStart() == null) {
ollaborations
return null;
allPredsDone = false;
}
l
resource
(exernal views)
break;
Base
}
Baby ataBase
}
(state)
return allPredsDone;
ResourcePane
}
A
C
D
l
MVC and DCA: JavaZone 2006
© Trygve Reenskaug 2006
2016.05.29
Slide 25
D
CA ex.2: frontloading
Java – areAllDone?
Model
activities
public Activity frontloader() {
for (Activity act : netBase.allActivities()) {
lgorithms
if (act.earlyStart() == null) {
(behavior)
Set<Activity> predSet = predecessorsOf(act);
dependencies
DependencyPanell
if (areAllDone(predSet)) {
frontloader = act;
network
return(frontloader);
private boolean areAllDone(Set<Activity> actSet) {
Base
}
boolean allPredsDone = true;
allocations
}
for ( Activity pred : actSet) {
}
GanttPane
if (pred.earlyStart() == null) {
ollaborations
return null;
allPredsDone = false;
}
l
resource
(exernal views)
break;
Base
}
Baby ataBase
}
(state)
return allPredsDone;
ResourcePane
}
A
C
D
l
MVC and DCA: JavaZone 2006
© Trygve Reenskaug 2006
2016.05.29
Slide 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: JavaZone 2006
© Trygve Reenskaug 2006
2016.05.29
Slide 27
MVC – DCA
Conclusion
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
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: JavaZone 2006
© Trygve Reenskaug 2006
2016.05.29
Slide 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-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 29
Download