+ All Categories
Home > Documents > Two System Architectures: MVC and DCA

Two System Architectures: MVC and DCA

Date post: 21-Jan-2016
Category:
Upload: finna
View: 27 times
Download: 0 times
Share this document with a friend
Description:
Two System Architectures: MVC and DCA. Spinoff from the BabyUML project for Readable Programs. Trygve Reenskaug Department of Informatics University of Oslo. [email protected] http://www.ifi.uio.no/~trygver. an Activity Network Planning example. My Problem. Project resources. User - PowerPoint PPT Presentation
47
© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 1 13.04.2006 16:32 Two System Two System Architectures: Architectures: MVC and DCA MVC and DCA Trygve Reenskaug Department of Informatics University of Oslo trygver@ifi.uio.no http://www.ifi.uio.no/~trygver Spinoff from Spinoff from the BabyUML project the BabyUML project for for Readable Programs Readable Programs
Transcript
Page 1: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 113.04.2006 16:32

Two System Architectures:Two System Architectures:MVC and DCAMVC and DCA

Trygve ReenskaugDepartment of InformaticsUniversity of Oslo

[email protected]://www.ifi.uio.no/~trygver

Spinoff from Spinoff from the BabyUML projectthe BabyUML projectfor for Readable ProgramsReadable Programs

Page 2: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 313.04.2006 16:32

an Activity Network Planningan Activity Network Planningexampleexample

Page 3: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 413.04.2006 16:32

Projectactivities

actDactB

actCactA

Projectresources

Usertools

My ProblemMy Problem

Undisciplined communication → Spaghetti

ClassClass

Class

actB

Class + superclasses + methods → Noodles

Page 4: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 513.04.2006 16:32

BabyUML Goal:BabyUML Goal:Readable ProgramsReadable Programs

The price of reliability is the pursuit of the utmost simplicity

(C.A.R. Hoare, 1980 Turing Award lecture)

Page 5: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 613.04.2006 16:32

The BabyComponent =The BabyComponent =an object encapsulating other objectsan object encapsulating other objects

network «Component»

resource «Component»

tool «Component»

network «Component»

resource «Component»

tool «Component»

Page 6: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 713.04.2006 16:32

Baby ComponentsBaby ComponentsUniverse of DiscourseUniverse of Discourse

demoData

resource

network

«component» babydemo

tool

«Interface»Observer

«Interface»DemoDataIntf

«Interface»NetworkIntf

«Class»ActivityDescr

«Interface»ResourceIntf

Page 7: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 813.04.2006 16:32

The BabyDemo programThe BabyDemo programdemodata + network + resource + tooldemodata + network + resource + tool

+IDE

Page 8: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 1113.04.2006 16:32

Baby ComponentsBaby ComponentsDivide and Conquer: the toolDivide and Conquer: the tool

demoData

resource

network

«co

mp

on

en

t» ba

by

de

mo

tool

«Interface»Observer

«Interface»DemoDataIntf

«Interface»NetworkIntf

«Class»ActivityDescr

«Interface»ResourceIntf

Page 9: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 1213.04.2006 16:32

Model – View - ControllerModel – View - Controllerbridge gapbridge gap Mental Model – ComputerMental Model – Computer

ModelUser

mental model

computer model

Page 10: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 1313.04.2006 16:32

Model – View - ControllerModel – View - ControllerMultiple Views on same ModelMultiple Views on same Model

ModelUser

mental model

computer model

Run Demo

View

1

**

Page 11: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 1413.04.2006 16:32

Model – View - ControllerModel – View - ControllerTool = Controller + ViewsTool = Controller + Views

ModelUser

View

Controller

*1

*

*

Tool

mental model

computer model

Run Demo

Page 12: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 1513.04.2006 16:32

MModelodel V Viewiew C ControllerontrollerRoles and ResponsibilitiesRoles and Responsibilities

Model Store domain information

View Present and edit domain information

Controller Build, manage and co-ordinate Views

Page 13: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 1613.04.2006 16:32

Example: babydemo.toolExample: babydemo.toolClass structureClass structure

Java.awt.Component java.applet.Appletjava.awt.Panel

Controller

ResourceViewButtonsView

java.awt.Button ActivityView

GanttViewDependencyView

Page 14: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 1713.04.2006 16:32

Example: babydemo.toolExample: babydemo.tool visual hierarchy visual hierarchy (associations)(associations)

Controller

ResourceViewButtonsView

java.awt.Button ActivityView

GanttViewDependencyView

1 111

1

*

1111

*

Page 15: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 1813.04.2006 16:32

Example: babydemo.toolExample: babydemo.toolMVC collaboration structureMVC collaboration structure

model.observed

view, observer: ResourceView

button: java.awt.Button

Tool

controller,observed, observer

view, observer: ButtonsView

view, observer: DependencyView

view, observer: GanttView

view, observer: ActivityView

Page 16: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 1913.04.2006 16:32

The Anatomy ofThe Anatomy ofbabyDemo.toolbabyDemo.toolcontroller : Controller

view :DependencyViewview

:ActivityView

heim.ifi.uio.no/~trygver/2006/roots-2006/babyExample4.html

Page 17: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 2013.04.2006 16:32

MVCMVCSynchronized SelectionSynchronized Selection

Usera view

actionPerformed()

observer*

pointAndClickMouse

controller

present

update()

selectedObject

selectionEvent()

notifyObserver()

Page 18: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 2113.04.2006 16:32

MVCMVCtool componenttool component

+IDE

Page 19: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 2613.04.2006 16:32

Baby Components: the networkBaby Components: the networkDivide and ConquerDivide and Conquer

demoData

resource

network

«co

mp

on

en

t» ba

by

de

mo

tool

«Interface»Observer

«Interface»DemoDataIntf

«Interface»NetworkIntf

«Class»ActivityDescr

«Interface»ResourceIntf

Page 20: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 2713.04.2006 16:32

The Simple ComponentThe Simple Componentindisciplined internalsindisciplined internals

façademethod

façademethod

receive message

actB

actA actC actD

Page 21: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 2813.04.2006 16:32

The Declarative ComponentThe Declarative ComponentMember Objects in micro databaseMember Objects in micro database

addDependency()

actDactC

actDactB

actCactA

actA actB actC actD

babyBase with Member Objectsand Member structure

newActivity()

newActivity()

addDependency()

babyBase interfacevoid newActivity

(String actName , …) void addDependency

(String predNam , String succNam) Set<ActivityIntf> allActivities

() Activity activityNamed

(String actNam)Set<ActivityIntf> predecessorsOf

(String actName) Set<ActivityIntf> successorsOf

(String actName)

Page 22: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 2913.04.2006 16:32

DCADCAseparate the whole from the Detailsseparate the whole from the Details

Inward-lookingmethods and fields

Outward-lookingmethods and fields

Componentlooks outward

Member Objectslook inward

Member Object

Page 23: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 3013.04.2006 16:32

Three simple operationsThree simple operations

Page 24: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 3113.04.2006 16:32

a DCA Component

The DCA ComponentThe DCA ComponentDData + ata + CCommunication + ommunication + AAlgorithmlgorithm

MaestroMethod

MaestroMethod

receive message

micro “database” with Member Objects and structure

actA actB actC actD

Data

Algorithm

Communication

?

Page 25: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 3213.04.2006 16:32

The DCA ComponentThe DCA Componentinvisible babyBaseinvisible babyBase

addDependency()

actDactC

actDactB

actCactA

actA actB actC actD

babyBase with Member Objectsand Member structure

newActivity()

babyBase interfacevoid newActivity

(String actName , …) void addDependency

(String predNam , String succNam) Set<ActivityIntf> allActivities

() privateprivate Activity activityNamed

(String actNam)privateprivate Set<ActivityIntf> predecessorsOf

(String actName) privateprivate Set<ActivityIntf> successorsOf

(String actName)

maestroonly

babyBaseonly

Page 26: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 3313.04.2006 16:32

public ActivityDescr public ActivityDescr activityDescriptorFor activityDescriptorFor (String actName)(String actName)

another Maestro Method

receive message

babyBase actDactC

actDactB

actCactA

actA actB actC actD

activityDescriptorFor(“actC”)

public class ActivityDescr { public String name; public Integer earlyStart, earlyFinish, duration, rank; public Color color; public Set<String> predecessors, successors;

public class ActivityImpl implements ActivityIntf { MemberBase babyBase; private String name; private Integer earlyStart, duration, rank = 0; private Color color = Color.gray;

Which activity?What are preds, succs??

Page 27: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 3413.04.2006 16:32

DescrCollab

activity successors predecessors * *

algorithmalgorithm activityDescriptorFor()activityDescriptorFor()needs both predecessors and successorsneeds both predecessors and successors

roles

Page 28: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 3513.04.2006 16:32

public public ActivityDescr ActivityDescr activityDescriptorFor activityDescriptorFor (String actName)(String actName)

MaestroMethod

receive message

micro“database” actDactC

actDactB

actCactA

actA actB actC actD

activityDescriptorFor(“actC”)

actB

actA actC actD

Data

Algorithm

Collaboration =Communication

context

actA actB actC actD

activity successors predecessors * *

DescrCollab

Page 29: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 3613.04.2006 16:32

“9.3.4 CollaborationUseA collaboration use represents the application of the pattern described by a collaboration to a specific situation involving specific classes or instances playing the roles of the collaboration.”

“9.3.3 CollaboratioA collaboration describes a structure of collaborating elements (roles), each performing a specialized function,

which collectively accomplish some desired functionality…

Thus, details, such as the identity or precise class of the actual participating instances are suppressed.”

UML 2.1: CollaborationUML 2.1: Collaboration

BabyUMLCollaboration

BabyUMLQuery

+

Page 30: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 3713.04.2006 16:32

Bind roles to Member Objects with queriesBind roles to Member Objects with queries

ActivityDescriptorCollab

activity successors predecessors * *

DescrCollab

activity successors predecessors * *

define successors (String actNam) asselect succfrom dependencieswhere pred.name = actNam

define query activity (String actNam) asselect actfrom activitieswhere act.name = actNam

define predecessors (String actNam) asselect predfrom dependencieswhere succ.name = actNam

Page 31: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 3813.04.2006 16:32

Algorithm Algorithm (maestro)(maestro)ActivityImpl:: activityDescriptor()ActivityImpl:: activityDescriptor()

Page 32: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 4213.04.2006 16:32

D C AD C ADDataata CCommunicationommunication AAlgorithmlgorithm

Data(MemberBase)

A MemberBase maintains the member objects and their structure

Communication(Component façade method)

Component operation realized by

1. establishing a collaboration of roleplaying objects

2. triggering role interaction

Algorithm(Member Object method)

Member object methods implement detailed algorithms

Page 33: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 4313.04.2006 16:32

babydemobabydemo Universe of Discourse Universe of Discourseinterface interface NetworkIntfNetworkIntf

Page 34: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 4413.04.2006 16:32

actB

actA actC actD

maestro methodmaestro methodvoidvoid frontload frontload (Integer firstWeek);(Integer firstWeek);

another Maestro Method

babyBase

receive message

actDactC

actDactB

actCactA

actA actB actC actD

frontload ( )

frontloaderpredecessors *frontCollab

define query frontActivities asselect actfrom activitieswhere

act.earlyStart.isNiland (

select succfrom dependencieswhere

pred = actand

pred.earlyStart.notNil) isEmpty

actB

actA actC acD

frontload (1)

actB

actA actC actD

actB

actA actC actD

actB

actA actC actD

actA actB actCactB actDactCactB

Page 35: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 4513.04.2006 16:32

babyBase.FrontCollabbabyBase.FrontCollabprotected class FrontCollab { ActivityIntf frontloader; Set<ActivityIntf> predecessors; FrontCollab() {

// activity that is ready to do : not done and all predecessors done frontloader = null; predecessors = new HashSet<ActivityIntf> (0); for (ActivityIntf act : activities) {

if (act.earlyStart() == null) { Set<ActivityIntf> preds = predecessorsOf(act.name()); boolean predsDone = true; for ( ActivityIntf pred : preds) {

if (pred.earlyStart() == null) { predsDone = false; break;

} }

if (predsDone) { frontloader = act; predecessors = preds;

break; } } } } }

Page 36: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 4613.04.2006 16:32

The DCA ComponentThe DCA ComponentDData + ata + CCommunication + ommunication + AAlgorithmlgorithm

FaçadeMethod

receive messagea DCA Component

Algorithms implemented as Methods in Member Objects

Data structure and objectscontained in micro ”database”

actA actB actC actD

Façade Method

1. creates Collaboration by binding Roles to Member Objectsthrough dynamic Queries.

2. triggers Communication as message interaction between Roles

FaçadeMethod

roleX roleY

actDactCactB

Page 37: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 4813.04.2006 16:32

• Reduce coupling by enforcing component encapsulation.• MVC to separate domain information and presentation

– Model components hold domain information– Tool gives user direct access to information

• View objects let user see and edit• Controller object coordinates views

• DCA to organize component internal Member Objects– Data: Member objects administred by BabyBase that ensured data

integrity• Conceptual Schema; BabyBase defines universe of discourse.• External schemas: BabyBase creates collaborations for the external

operations• (Internal schema is the Member Object classes).

– Communication: Maestro methods in Component object triggers Member Object behavior

– Algorithms: What’s left in the Member Objects.

Summary and ConclusionSummary and Conclusion““make it so simple that there are obviously no deficiencies”make it so simple that there are obviously no deficiencies”

• Reduce coupling by enforcing component encapsulation.• MVC to separate domain information and presentation

– Model components hold domain information– Tool gives user direct access to information

• View objects let user see and edit• Controller object coordinates views

• DCA to organize component internal Member Objects– Data: Member objects administred by BabyBase that ensured data

integrity• Conceptual Schema; BabyBase defines universe of discourse.• External schemas: BabyBase creates collaborations for the external

operations• (Internal schema is the Member Object classes).

– Communication: Maestro methods in Component object triggers Member Object behavior

– Algorithms: What’s left in the Member Objects.

Page 38: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 4913.04.2006 16:32

The EndThe End

More info at http://heim.ifi.uio.no/~trygver

Claim: MVC and DCA make for self-documenting code

Page 39: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 5013.04.2006 16:32

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

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.

Trygve Reenskaug: The BabyUML Discipline of Programming. ECMDA 2005 keynote. http://heim.ifi.uio.no/~trygver/2005/babyuml/ECMDA2005-keynote.ppt

Edsger Dijkstra: A Discipline of Programming, 1976

Charles Antony Richard Hoare: The Emperor's Old Clothes. 1980 Turing Award lecture. Comm.ACM 24, 2 (Feb. 1981)

[UML] Unified Modeling Language: Superstructure. Version 2.1. Object Management Group (OMG) document ptc/06-04-02. http://www.omg.org

Trygve Reenskaug: Empowering People with BabyUML: A sixth GenerationProgramming Language. Opening talk, ECOOP 2004, Oslo.http://heim.ifi.uio.no/~trygver/2004/ECOOP-04/EcoopHandout.pdf

Trygve Reenskaug: Original MVC notes from Xerox PARC:http://heim.ifi.uio.no/~trygver/1979/mvc-1/1979-05-MVC.pdfhttp://heim.ifi.uio.no/~trygver/1979/mvc-2/1979-12-MVC.pdf

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 Style on the Maintainability of Object-Oriented Software, Simula Research Laboratory Technical Report 2003-6http://www.simula.no/publication_one.php?publication_id=601

Page 40: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 5113.04.2006 16:32

ZZZTheZZZThe babydemo Componentbabydemo ComponentUniverse of DiscourseUniverse of Discourse

demoData

resource

network

«component» babydemo

tool

«Interface» ResourceIntf

«Interface» DemoDataIntf

«Interface» NetworkIntf

«Class»ActivityDescr

Page 41: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 5513.04.2006 16:32

Divide and ConquerDivide and Conquerthethe networknetwork ComponentComponent

«Class» DemoData

DemoDataIntf

«Class» resource

ResourceIntf

«DCA-component»network

NetworkIntf

«component» babydemo

«MVC-component»tool

Applet

«Class»ActivityDescr

Page 42: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 5613.04.2006 16:32

babydemo.babydemo.NetworkIntfNetworkIntf+IDE

Page 43: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 5913.04.2006 16:32

public void public void newActivitynewActivity(String actName , Integer duration, Color color);(String actName , Integer duration, Color color);

MaestroMethod

newActivity()

receive message

babyBase with Member Objects and structure

actA actB actC actD

Page 44: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 6013.04.2006 16:32

public void public void addDependencyaddDependency(String fromName , String toName);(String fromName , String toName);

addDependency

MaestroMethod

receive message

babyBase actDactC

actDactB

actCactA

actA actB actC actD

Page 45: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 6113.04.2006 16:32

babydemo.babydemo.NetworkIntfNetworkIntf

Page 46: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 6213.04.2006 16:32

maestro methodmaestro methodpublic public List<String> activityNames()List<String> activityNames()

Page 47: Two System Architectures: MVC and DCA

© Trygve Reenskaug 2006 MVC & DCA - ROOTS 2006 Slide 6313.04.2006 16:32

babydemo.babydemo.NetworkIntfNetworkIntf


Recommended