: A DC d

advertisement
© Trygve Reenskaug 2006
2006.08.11
Slide 1
© Trygve Reenskaug 2006
©2006 Trygve Reenskaug
MVC and DCA: JavaZone 2006
2006.08.11
Slide 3
- View - Controller
Data - Collaboration - Algorithm
e.g.: Model
High level programming disciplines.
BabyUML goal:
(C.A.R. Hoare, 1980 Turing Award lecture)
The price of reliability is the pursuit of
the utmost simplicity
BabyUML slogan:
The BabyUML Project
MVC and DCA: JavaZone 2006
trygver@ifi.uio.no
http://heim.ifi.uio.no/~trygver/2006/09-JavaZone/
Trygve Reenskaug
Department of Informatics
University of Oslo
MVC and DCA:
Two complimentary
system architectures.
MVC and DCA: JavaZone 2006
2006.08.11
View
MVC and DCA: JavaZone 2006
© Trygve Reenskaug 2006
Slide 2
2006.08.11
Slide 4
Model
computer
information
View bridges gap between
user Mental model and
Computer information
mental
model
User
© Trygve Reenskaug 2006
Model – View - Controller
MVC and DCA: JavaZone 2006
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.
All rights reserved.
This presentation is copyright
©2006 Trygve Reenskaug
Oslo, Norway.
Legal Notice
Friday, August 11, 2006
1
View
*
1
Controller
*
*
Model
computer
information
© Trygve Reenskaug 2006
Slide 5
2006.08.11
Slide 7
panelView
:DependencyPanel
MVC Demo
controller : Controller
©2006 Trygve Reenskaug
MVC and DCA: JavaZone 2006
2006.08.11
The Anatomy of
© Trygve Reenskaug 2006
:ActivityView
MVC and DCA: JavaZone 2006
Controller creates and coordinates
multiple Views
Run Demo
User
mental
model
Model – View - Controller
MVC and DCA: JavaZone 2006
2006.08.11
MVC and DCA: JavaZone 2006
© Trygve Reenskaug 2006
Slide 6
2006.08.11
present
isSelected()
Slide 8
activityView*
selectionChanged()
controller
actionPerformed()
inputView
User
pointAndClickMouse
MVC
© Trygve Reenskaug 2006
example
Synchronized Selection
MVC and DCA: JavaZone 2006
http://heim.ifi.uio.no/~trygver/2006/09-JavaZone/babyExample4.html
MVC Demo
Friday, August 11, 2006
2
2006.08.11
2006.08.11
derived attributes
© Trygve Reenskaug 2006
(behavior)
methods
as a single Object
the Model
© Trygve Reenskaug 2006
©2006 Trygve Reenskaug
MVC and DCA: JavaZone 2006
illustration copied from
The Java Tutorial
Copyright 1995-2005
Sun Microsystems, Inc.
MVC and DCA: JavaZone 2006
public boolean isSelected(Activity act)
{
present
return ( selection == act );
}
selection = source.activity();
actionPerformed()
for (ActivityView
view : activityViews) {
view.selectionChanged();selectionChanged()
}
isSelected()
repaint();
}
(state)
Slide 11
owned
attributes
Slide 9
controller
leafView*
User
public void actionPerformed(ActionEvent e) {
pointAndClickMouse
ActivityView source = (ActivityView)e.getSource();
class Controller {
Activity
selection;
inputView
example
Synchronized Selection
MVC
MVC and DCA: JavaZone 2006
© Trygve Reenskaug 2006
Model
2006.08.11
Slide 10
MVC and DCA: JavaZone 2006
(behavior)
Algorithms
© Trygve Reenskaug 2006
dependencies
Data
activities
Slide 12
(owned attributes)
memberObject
2006.08.11
(derived attributes)
Collaborations
DCA Component
the DCA Component
Data + Collaboration + Algorithm
MVC and DCA: JavaZone 2006
controller
Model – View - Controller
Friday, August 11, 2006
3
the Model
Collaborations
2006.08.11
Slide 13
(owned attributes)
allocations
network
Base
dependencies
activities
Data
netBase
Slide 15
resource
©2006 Trygve Reenskaug
2006.08.11
allocations
Model
MVC and DCA: JavaZone 2006
ResourcePanel
© Trygve Reenskaug 2006
Java as schema language
public class MemberDependency {
GanttPanel
private Activity predecessor, successor; ...
2006.08.11
public class Activity {
private
Integer earlyStart, earlyFinish, duration;
DependencyPanel
private String name;
private Color color = Color.gray; ….
Data
Slide 16
(state)
Data
allocations
dependencies
activities
Slide 14
allocations
dependencies
activities
resource
MVC and DCA: JavaZone 2006
© Trygve Reenskaug 2006
UML as schema language
ResourcePanel
GanttPanel
predecessor
2006.08.11
public class BabyBase extends Observable implements Observer {
private Set<Activity> activities;
private Set<MemberDependency> dependencies;
DCA
© Trygve Reenskaug 2006
baby database - Java
MVC and DCA: JavaZone 2006
ResourcePanel
GanttPanel
DependencyPanel
Model
Collaborations
Algorithm
netBase
*
Collaborations activities
Activity
name
earlyStart
successor Algorithms
earlyFinish
*
duration
dependencies
DependencyPanel
Dependency
color
Model
baby database – UML schema
DCA
© Trygve Reenskaug 2006
(derived attributes)
rankedCollab
frontloadCollab
Data
the structure
MVC -- DCA
Friday, August 11, 2006
resource
MVC and DCA: JavaZone 2006
(behavior)
frontload
Algorithms
DCA Component
as a DCA Component
MVC and DCA: JavaZone 2006
netBase
4
DependencyPanel
© Trygve Reenskaug 2006
2006.08.11
(exernal view)
Collaboration
Slide 17
(state)
resource
Base
Data
allocations
network
Base
dependencies
activities
©2006 Trygve Reenskaug
© Trygve Reenskaug 2006
2006.08.11
(exernal view)
Collaboration
Slide 19
(state)
Data
allocations
resource
ResourcePane
l
MVC and DCA: JavaZone 2006
GanttPane
l
dependencies
DependencyPanel
layout Algorithm
(behavior)
activities
RankedCollab
Model
DCA ex.1: Collaboration
RankedCollab is a Data projection
ResourcePane
l
MVC and DCA: JavaZone 2006
GanttPane
l
(behavior)
layout Algorithm
Model
is responsible for layout algorithm
DCA ex.1:
MVC and DCA: JavaZone 2006
netBase
activities
Activities
}
ResourcePane
l
MVC and DCA: JavaZone 2006
GanttPane
l
Model
2006.08.11
(exernal views)
activities
Slide 18
Slide 20
resource
Base
allocations
network
Base
dependencies
Collaborations
© Trygve Reenskaug 2006
define activityListAtRank(Integer rank) as
select act
DependencyPanel
from activities act
where rank(act) = rank
RankedCollab
RankedCollab
query
2006.08.11
(exernal views)
resource
Base
network
Base
Resource
allocations
Allocations
Collaborations
© Trygve Reenskaug 2006
yPos = yPos + gridY;
// misc. computations
DCA ex.1:
ResourcePane
l
MVC and DCA: JavaZone 2006
GanttPane
l
}
}
for (Activity act : rankedCollab.activityListAtRank(rank)) {
ActivityView actView = new ActivityView(controller, act, 24) ;
dependencies
Dependencies
add(actView);
DependencyPanel
// compute xPos, yPos
for (int rank=0; rank <= rankedCollab.maxRank(); rank++) {
// Compute gridX, gridY, x0, y0, buttonExtent
private void addActivityViews() {
Model
DependencyPanel
responsible for layout Algorithm
DCA ex.1:
Friday, August 11, 2006
5
Java
2006.08.11
DCA ex.2: frontloading
© Trygve Reenskaug 2006
activities
Slide 21
resource
Base
© Trygve Reenskaug 2006
C
©2006 Trygve Reenskaug
ResourcePane
l
MVC and DCA: JavaZone 2006
A
2006.08.11
D
Slide 23
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)
}
Model
network
Base
allocations
frontload algorithm - Java
MVC and DCA: JavaZone 2006
ResourcePanel
(exernal views)
activities
dependencies
Collaborations
Model
RankedCollab
activityListAtRank(Integer rank) {
List<Activity> activityListAtRank
define activityListAtRank(Integer
rank) as
= new ArrayList<Activity>();
act
for select
(Activity
act
:
bBase.
allActivities())
{
from DependencyPanel
activities act
if (rankOf(act) == rank) {
where rank(act) = rank
activityListAtRank .add(act);
}
}
GanttPane
return activityListAtRank ;
l
}
RankedCollab
public List<Activity>
DCA ex.1:
MVC and DCA: JavaZone 2006
© Trygve Reenskaug 2006
Algorithms
ResourcePane
l
MVC and DCA: JavaZone 2006
© Trygve Reenskaug 2006
2006.08.11
Slide 24
(state)
BabyDataBase
activities
Slide 22
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
l pred.earlyStart != null)
resource
(exernal views)
) someInstance
Base
Model
query - frontloader
(state)
allocations
network
Base
resource
Base
BabyDataBase
(exernal views)
2006.08.11
activities
dependencies
Collaborations
CA ex.2: frontloading
D
ResourcePane
l
MVC and DCA: JavaZone 2006
GanttPane
l
(behavior)
Algorithms
Model
DCA ex.2: frontloading
Data – Collaboration – Algorithm
Friday, August 11, 2006
6
Model
Java - frontloader
activities
C
Critique
MVC – DCA
© Trygve Reenskaug 2006
2006.08.11
D
Slide 25
© Trygve Reenskaug 2006
©2006 Trygve Reenskaug
MVC and DCA: JavaZone 2006
• if the Algorithm spans several objects.
– create a separate Algorithm class
2006.08.11
• if Algorithms need to see data from different perspectives.
– separate out data queries in Collaboration classes
• when the data structure is complex.
– simplify Data with a baby database
• DCA
• when the user needs to see them simultaneously.
Slide 27
– write a Controller class to create and coordinate the Views
• when the user needs to see the Model from several perspectives.
– write several View classes for the same Model class
• when GUI and Model are deployed on different machine.
• when the application code is complex.
• MVC
– separate Model and View
ResourcePane
}
l
MVC and DCA: JavaZone 2006
A
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;
D
CA ex.2: frontloading
MVC and DCA: JavaZone 2006
ResourcePane
}
l
MVC and DCA: JavaZone 2006
A
C
2006.08.11
Slide 26
MVC and DCA: JavaZone 2006
© Trygve Reenskaug 2006
2006.08.11
Slide 28
CDA facilitates simplicity
because it separates concern
and lets you use your whole brain
™Your left brain works up to the whole step by step,
focusing on details; makes logical deductions; verbal
9use it to create and understand algorithms
™Your right brain sees the whole first, then the
details; makes lateral connections; pictorial
9use it to create and understand data models and
collaborations
Conclusion
MVC – DCA
© Trygve Reenskaug 2006
D
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;
Model
Java – areAllDone?
areAllDone?
CA ex.2: frontloading
D
Friday, August 11, 2006
7
mailto: trygver ‘at’ ifi.uio.no
© Trygve Reenskaug 2006
©2006 Trygve Reenskaug
MVC and DCA: JavaZone 2006
Donald A. Norman: The Design of Everyday Things.
Doubleday/Currency 1990. ISBN 0-385-26774-6
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
2006.08.11
Slide 29
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
Cattell, Barry: The Object Data Standard: ODMG 3.0.
Academic Press, London, 2000. ISBN 1-55860-647-4
Unified Modeling Language: Superstructure. Version 2.1.
Object Management Group (OMG) document ptc/06-04-02. http://www.omg.org
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
Charles Antony Richard Hoare: The Emperor's Old Clothes. 1980 Turing Award lecture. Comm.ACM 24, 2 (Feb. 1981)
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
dca-demo example code:
http://heim.ifi.uio.no/~trygver/2006/09-JavaZone/BabyProject-2/
http://www.ifi.uio.no/~trygver
More reading
MVC and DCA: JavaZone 2006
Friday, August 11, 2006
8
Download