470 likes | 573 Views
Two System Architectures: MVC and DCA. Spinoff from the BabyUML project for Readable Programs. Trygve Reenskaug Department of Informatics University of Oslo. trygver@ifi.uio.no http://www.ifi.uio.no/~trygver. an Activity Network Planning example. My Problem. Project resources. User
E N D
Two System Architectures:MVC and DCA Spinoff from the BabyUML project for Readable Programs Trygve Reenskaug Department of Informatics University of Oslo trygver@ifi.uio.no http://www.ifi.uio.no/~trygver MVC & DCA - ROOTS 2006
an Activity Network Planningexample MVC & DCA - ROOTS 2006
My Problem Project resources User tools Project activities actA actC actB actB actD Class Class Class Undisciplined communication →Spaghetti Class + superclasses + methods →Noodles MVC & DCA - ROOTS 2006
BabyUML Goal:Readable Programs The price of reliability is the pursuit of the utmost simplicity (C.A.R. Hoare, 1980 Turing Award lecture) MVC & DCA - ROOTS 2006
The BabyComponent =an object encapsulating other objects resource «Component» resource «Component» tool «Component» tool «Component» network «Component» network «Component» MVC & DCA - ROOTS 2006
Baby ComponentsUniverse of Discourse «component» babydemo demoData tool «Interface» DemoDataIntf resource «Interface» Observer «Interface» ResourceIntf network «Interface» NetworkIntf «Class» ActivityDescr MVC & DCA - ROOTS 2006
The BabyDemo programdemodata + network + resource + tool +IDE MVC & DCA - ROOTS 2006
Baby ComponentsDivide and Conquer: the tool demoData tool «Interface» DemoDataIntf resource «component» babydemo «Interface» Observer «Interface» ResourceIntf network «Interface» NetworkIntf «Class» ActivityDescr MVC & DCA - ROOTS 2006
Model – View - Controllerbridge gapMental Model – Computer mental model computer model Model User MVC & DCA - ROOTS 2006
Model – View - ControllerMultiple Views on same Model 1 View * * mental model computer model Model User Run Demo MVC & DCA - ROOTS 2006
Model – View - ControllerTool = Controller + Views Controller * 1 * * View Tool mental model computer model Model User Run Demo MVC & DCA - ROOTS 2006
Model View ControllerRoles and Responsibilities MVC & DCA - ROOTS 2006
Example: babydemo.toolClass structure java.applet.Applet java.awt.Panel Java.awt.Component Controller ButtonsView DependencyView GanttView ResourceView java.awt.Button ActivityView MVC & DCA - ROOTS 2006
Example: babydemo.tool visual hierarchy (associations) ActivityView Controller 1 1 1 1 1 ButtonsView DependencyView GanttView ResourceView 1 1 1 1 * * java.awt.Button MVC & DCA - ROOTS 2006
Example: babydemo.toolMVC collaboration structure Tool controller, observed, observer model. observed view, observer: ButtonsView view, observer: DependencyView view, observer: GanttView view, observer: ResourceView button: java.awt.Button view, observer: ActivityView MVC & DCA - ROOTS 2006
The Anatomy ofbabyDemo.tool controller : Controller view :DependencyView view :ActivityView heim.ifi.uio.no/~trygver/2006/roots-2006/babyExample4.html MVC & DCA - ROOTS 2006
MVCSynchronized Selection controller observer* a view update() selectedObject present User pointAndClickMouse actionPerformed() selectionEvent() notifyObserver() MVC & DCA - ROOTS 2006
MVCtool component +IDE MVC & DCA - ROOTS 2006
Baby Components: the networkDivide and Conquer demoData tool «Interface» DemoDataIntf resource «component» babydemo «Interface» Observer «Interface» ResourceIntf network «Interface» NetworkIntf «Class» ActivityDescr MVC & DCA - ROOTS 2006
The Simple Componentindisciplined internals actD actA actC actB receive message façademethod façademethod MVC & DCA - ROOTS 2006
The Declarative ComponentMember Objects in micro database babyBase interface void 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) add Dependency() newActivity() actA actC actB actD actC actD actA actB actC actD add Dependency() newActivity() babyBase with Member Objects and Member structure MVC & DCA - ROOTS 2006
DCAseparate the whole from the Details Component looks outward Outward-lookingmethods and fields Member Object Inward-lookingmethods and fields Member Objects look inward MVC & DCA - ROOTS 2006
Three simple operations MVC & DCA - ROOTS 2006
The DCA ComponentData + Communication + Algorithm receive message a DCA Component MaestroMethod MaestroMethod actA actB actC actD Communication Algorithm micro “database” with Member Objects and structure Data ? MVC & DCA - ROOTS 2006
The DCA Componentinvisible babyBase babyBase interface void newActivity(String actName , …) void addDependency(String predNam , String succNam) Set<ActivityIntf> allActivities() privateActivity activityNamed(String actNam) private Set<ActivityIntf> predecessorsOf(String actName) private Set<ActivityIntf> successorsOf(String actName) actA actC actB actD actC actD maestro only actA actB actC actD babyBase only add Dependency() newActivity() babyBase with Member Objects and Member structure MVC & DCA - ROOTS 2006
public ActivityDescr activityDescriptorFor (String actName) actA actC actB actD actC actD receive message public class ActivityDescr { public String name; public Integer earlyStart, earlyFinish, duration, rank; public Color color; public Set<String> predecessors, successors; another Maestro Method activityDescriptorFor(“actC”) Which activity? What are preds, succs?? public class ActivityImpl implements ActivityIntf { MemberBase babyBase; private String name; private Integer earlyStart, duration, rank = 0; private Color color = Color.gray; actA actB actC actD babyBase MVC & DCA - ROOTS 2006
algorithmactivityDescriptorFor()needs both predecessors and successors DescrCollab * * predecessors activity successors roles MVC & DCA - ROOTS 2006
public ActivityDescr activityDescriptorFor (String actName) actD actA actC actB actA actB actC actD actA actC DescrCollab Collaboration = Communication context actB actD * * predecessors activity successors actC actD Algorithm Data receive message MaestroMethod activityDescriptorFor(“actC”) actA actB actC actD micro “database” MVC & DCA - ROOTS 2006
“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: Collaboration BabyUML Collaboration + “9.3.4 CollaborationUse A collaboration use represents the application of the pattern described by a collaboration to a specific situation involving specific classes or instances playingthe roles of the collaboration.” BabyUML Query MVC & DCA - ROOTS 2006
define successors (String actNam) as select succ from dependencies where pred.name = actNam Bind roles to Member Objects with queries ActivityDescriptorCollab DescrCollab * * predecessors predecessors activity activity successors successors * * define query activity (String actNam) as select act from activities where act.name = actNam define predecessors (String actNam) as select pred from dependencies where succ.name = actNam MVC & DCA - ROOTS 2006
Algorithm (maestro)ActivityImpl:: activityDescriptor() MVC & DCA - ROOTS 2006
D C ADataCommunicationAlgorithm MVC & DCA - ROOTS 2006
babydemo Universe of Discourseinterface NetworkIntf MVC & DCA - ROOTS 2006
define query frontActivities as select act from activities where act.earlyStart.isNil and ( select succ from dependencies where pred = act and pred.earlyStart.notNil ) isEmpty maestro methodvoid frontload (Integer firstWeek); receive message actD acD actD actA actA actA actC actC actC actD actD actA actA actC actC actB actB actB * predecessors frontloader actB actB actA actC frontCollab actB actD actC actD actB actB actD actB actA actC actC another Maestro Method frontload ( ) frontload (1) actA actB actC actD babyBase MVC & DCA - ROOTS 2006
protectedclass 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; } } } } } babyBase.FrontCollab MVC & DCA - ROOTS 2006
The DCA ComponentData + Communication + Algorithm roleX roleY actA actB actC actD Data structure and objects contained in micro ”database” receive message a DCA Component • Façade Method • creates Collaboration by binding Roles to Member Objectsthrough dynamic Queries. • triggers Communication as message interactionbetween Roles FaçadeMethod FaçadeMethod actD actB actC Algorithmsimplemented as Methodsin Member Objects MVC & DCA - ROOTS 2006
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 Viewobjects 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 Conclusion“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. MVC & DCA - ROOTS 2006
The End Claim: MVC and DCA make for self-documenting code More info athttp://heim.ifi.uio.no/~trygver MVC & DCA - ROOTS 2006
http://www.ifi.uio.no/~trygvermailto: 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 More reading …. MVC & DCA - ROOTS 2006
ZZZThebabydemo ComponentUniverse of Discourse «component» babydemo tool demoData resource «Interface» DemoDataIntf «Interface» ResourceIntf network «Interface» NetworkIntf «Class»ActivityDescr MVC & DCA - ROOTS 2006
Divide and ConquerthenetworkComponent «Class» DemoData DemoDataIntf «Class» resource ResourceIntf «MVC-component» tool «Class»ActivityDescr «DCA-component» network Applet NetworkIntf «component» babydemo MVC & DCA - ROOTS 2006
babydemo.NetworkIntf +IDE MVC & DCA - ROOTS 2006
public void newActivity(String actName , Integer duration, Color color); actA actB actC actD receive message newActivity() MaestroMethod babyBase with Member Objects and structure MVC & DCA - ROOTS 2006
public void addDependency(String fromName , String toName); actA actC actB actD actC actD receive message MaestroMethod add Dependency actA actB actC actD babyBase MVC & DCA - ROOTS 2006
babydemo.NetworkIntf MVC & DCA - ROOTS 2006
maestro methodpublic List<String> activityNames() MVC & DCA - ROOTS 2006
babydemo.NetworkIntf MVC & DCA - ROOTS 2006