Models and Reality Master Program Execution with DCI

  • Slides: 40
Download presentation
Models and Reality: Master Program Execution with DCI UML China 2010 Trygve Reenskaug Dept.

Models and Reality: Master Program Execution with DCI UML China 2010 Trygve Reenskaug Dept. of Informatics University of Oslo heim. ifi. uio. no/~trygver/themes/babyide UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 1

Two commonly believed Fallacies End users cannot understand modern programs FALSE BECAUSE: Object Models

Two commonly believed Fallacies End users cannot understand modern programs FALSE BECAUSE: Object Models are understandable BUT: Code must implement user mental model Programmers cannot read modern programs FALSE BECAUSE: Object systems can be coded to be readable and checkable BUT: Code must describe program runtime structure UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 3

Reality program execution creates value Personal plans Project control Accounting Calender IDE UML-China 2010

Reality program execution creates value Personal plans Project control Accounting Calender IDE UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 4

End User System Experience End User mental model domain model (what the system IS)

End User System Experience End User mental model domain model (what the system IS) use cases (what the system DOES) Runtime (objects and interactions) Chasm Compile time (classes, superclasses) code class model Programmer mental model UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 5

Plan The User’s mental model • Object Orientation • CRC Cards • Lean and

Plan The User’s mental model • Object Orientation • CRC Cards • Lean and Agile The Programmer’s mental model Defect removal Conclusion UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 6

Object-Orientation: networks of communicating objects Alan Kay: Each Smalltalk object is a recursion on

Object-Orientation: networks of communicating objects Alan Kay: Each Smalltalk object is a recursion on the entire possibilities of the computer. Thus its semantics are a bit like having thousands and thousands of computers all hooked together by a very fast network http: //gagne. homedns. org/~tgagne/contrib/Early. History. ST. html The essence of object orientation is the interchange of messages that takes place in the space between the objects UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 7

True Object Orientation Objects as participants in commnication receive me tho ds me mo

True Object Orientation Objects as participants in commnication receive me tho ds me mo ry receive me tho ds UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 me mo ry 8

End User performs a Money Transfer What the System DOES UML-China 2010 © Trygve

End User performs a Money Transfer What the System DOES UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 9

End User’s Mental Model What the system DOES Customer Bank From. Account To. Account

End User’s Mental Model What the system DOES Customer Bank From. Account To. Account transfer ( amount, from. Account, to. Account) transfer (. . . ) deposit (. . . ) UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 10

Three Use Case Executions Money Transfers use case execution Class ATM Class Savings. Account

Three Use Case Executions Money Transfers use case execution Class ATM Class Savings. Account Class Checking. Account UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 11

Name the objects by the roles they play in the Interaction use case executions

Name the objects by the roles they play in the Interaction use case executions ID 662454 136585 748534 995124 254967 245872 554782 221483 254967 UML-China 2010 © Trygve Reenskaug 2010 Class ATM Savings. Account Checking. Account ATM Checking. Account Savings. Account ATM Checking. Account --- 05. 12. 2020 Role Bank From. Account To. Account --- 12

CRC Class – Responsibility – Collaboration Wikipedia: Sloppy thinking CRC cards are usually created

CRC Class – Responsibility – Collaboration Wikipedia: Sloppy thinking CRC cards are usually created from index cards on which are written: • The class name • Its Super and Sub classes (if applicable) • The responsibilities of the class. • The names of other classes with which the class will collaborate to fulfill its responsibilities. • Author UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 13

CRC Candidate – Responsibility – Collaboration CRC cards are usually created from index cards

CRC Candidate – Responsibility – Collaboration CRC cards are usually created from index cards on which are written: • The role name. • The responsibilities of the roles (and the objects that play them). • The names of other roles with which the role will collaborate to fulfill its responsibilities. • Author. Candidate role – Responsibility -- Collaboration Wirfs-Brock; Mc. Kean: Object Design. Roles, Responsibilities, and Collaborations UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 14

CRC Cards Example role name = Bank responsibility = collaborators = To serve the

CRC Cards Example role name = Bank responsibility = collaborators = To serve the customer with a transfer of funds From. Account role name = To. Account responsibility = collaborators = To transfer funds from this account to its collaborator To. Account UML-China 2010 responsibility = To receive funds as part of a funds transfer © Trygve Reenskaug 2010 collaborators = none 05. 12. 2020 15

Summary Object Models are understandable End user mental model explains how the system works.

Summary Object Models are understandable End user mental model explains how the system works. End user mental model is an object model: Objects • Can store data • Can handle received messages • Can send messages to other objects Objects interact to to achieve a use case Objects are named by the role they play in the interaction UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 16

Coplien, Bjørnvig: Lean Architecture ISBN: 978 -0 -470 -68420 -7 Building Software as if

Coplien, Bjørnvig: Lean Architecture ISBN: 978 -0 -470 -68420 -7 Building Software as if people mattered No waste Get it right the first time! Be prepared for changes! Lean Principle: ”everybody, all together, from early on. ” System architecture shall reflect the end user's mental model. Architecture has two parts: What the system IS: Its state What the system DOES: Its behavior Architecture a skeleton program UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 17

Plan The User’s mental model • Object Orientation • CRC Cards • Lean and

Plan The User’s mental model • Object Orientation • CRC Cards • Lean and Agile The Programmer’s mental model • The Chasm between. Code and Execution • What the system IS – What the system DOES • Separation of concerns: Contexts with Roles • DCI: Data – Context – Interaction Defect removal Conclusion UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 18

Gamma, Helm, Johnson, Vlissides: Design Patterns An object-oriented program's run-time structure often bears little

Gamma, Helm, Johnson, Vlissides: Design Patterns An object-oriented program's run-time structure often bears little resemblance to its code structure. • The code structure is frozen at compile-time; it consists of classes in fixed inheritance relationships. • The run-time structure consists of rapidly changing networks of communicating objects. It's clear that code won't reveal everything about how a system will work. [GOF p. 22, 23] UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 19

The Essence of Object Orientation ü a class reveals everything about how an instance

The Essence of Object Orientation ü a class reveals everything about how an instance will handle an incoming message and reveals nothing about its collaborator or why the message was sent. ü an object by itself is not interesting ü the essence of object orientation is that objects communicate to achieve a common goal A We need explicit code that clearly specifies the Contexts, i. e. , the networks of communicating roles UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 20

Class Hierachy is Irrelevant for program execution Wikipedia: Code refactoring is the process of

Class Hierachy is Irrelevant for program execution Wikipedia: Code refactoring is the process of changing a computer program's source code without modifying its external functional behavior. Object copy Shape center area F_Circle radius UML-China 2010 copy center area radius Polygon vertices © Trygve Reenskaug 2010 F_Polygon copy center area vertices 05. 12. 2020 21

The Chasm between End User and Programmer End User mental model domain model (what

The Chasm between End User and Programmer End User mental model domain model (what the system IS) use cases (what the system DOES) Runtime (objects and interactions) Chasm Compile time (classes, superclasses) code class model Programmer mental model UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 22

Use Case Context and Roles Environment Customer transfer ( amount, from. Account, to. Account)

Use Case Context and Roles Environment Customer transfer ( amount, from. Account, to. Account) Bank. Transfer. Context role Bank role From. Account role To. Account transfer (. . ) deposit (. . ) role methods UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 23

Each Use Case Is Executed in a Context-2 Context-1 Use case-2 Use ca se-1

Each Use Case Is Executed in a Context-2 Context-1 Use case-2 Use ca se-1 Use case-3 Context-3 Role binding +Role Method injection UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 24

Three Perspectives Data – Context - Interaction Compile time Data, Context, Interaction Object model

Three Perspectives Data – Context - Interaction Compile time Data, Context, Interaction Object model code Data – What-The-System-IS Implementation of user’s domain model Dumb, dumb classes and superclasses without interaction code. Context – The Roles Participating in a Use Case Roles and role structure Select objects to play the roles. Inject role methods into selected objects (or their classes) Trigger Interaction – What-The-System-DOES Role Methods direct the execution of the Use Case UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 25

Programmer’s Mental Model Data Perspective domain model End User Conceptual schema «realize» Class attributes

Programmer’s Mental Model Data Perspective domain model End User Conceptual schema «realize» Class attributes + local methods «instantiate classes to object» data objects UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 26

Programmer’s Mental Model Context Perspective End User use cases Environment use case Context Role

Programmer’s Mental Model Context Perspective End User use cases Environment use case Context Role Bind roles to objects data objects UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 27

Programmer’s Mental Model Interaction Perspective Context Role Method definitions Role. A>> public void frontload.

Programmer’s Mental Model Interaction Perspective Context Role Method definitions Role. A>> public void frontload. Network(Integer start. Week) { Role. B. frontload(start. Week); set. Changed(); notify. Observers("ACTIVITY"); } Role. B>>public void frontload(Integer start. Week) { // reset all for (Activity act : All. Activities) { act. set. Early. Start(null); } // frontload all Activity frontloader; while (Current. Context. rebind(); Activity != null) { Integer early. Start = start. Week; for (Activity pred : Predecessors) { early. Start = Math. max(early. Start, pred. early. Finish() + 1); } Activity. set. Early. Start(early. Start); } } Class definitions package babydemo 3. model; import babydemo 3. model. Model; package babydemo 3. model. algorithm; import babydemo 3. model. collaboration. *; import babydemo 3. model. Model; import babydemo 3. model. algorithm. *; import babydemo 3. model. data. Activity; import babydemo 3. model. data. *; import babydemo 3. model. collaboration. Frontload. Collab; import java. util. *; public class Case { import java. awt. Color; private Plan model; public class Model extends Observable { } private Net. Base net. Base; private Resource resource; public void frontload(Integer start. Week) { public Model()//{}reset all forresource() (Activity act public Resource {} : All. Activities) { act. set. Early. Start(null); public void reset() {} } public void add. Activity(String name, Integer duration, Color color) {} // frontload all public void add. Dependency(String pred. Name, String succ. Name) {} Activity frontloader; while (Current. Context. reselect(); Activity != null) { public void frontload. Network(Integer start. Week) { Integer early. Start = start. Week; Role. B. frontload(start. Week); for (Activity pred : Predecessors) { set. Changed(); early. Start = Math. max(early. Start, pred. early. Finish() + 1); notify. Observers("ACTIVITY"); } } Activity. set. Early. Start(early. Start); } } } inject role methods UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 28

Programmer’s Mental Model The Whole Story domain model use cases Conceptual schema Environment use

Programmer’s Mental Model The Whole Story domain model use cases Conceptual schema Environment use case task Context realize Class attributes + local methods + role methods Role Inject role methods «instantiate classes to objects» Role «bind roles to objects» interaction data objects UML-China 2010 End User © Trygve Reenskaug 2010 05. 12. 2020 29

Plan The User’s mental model • Object Orientation • CRC Cards • Lean and

Plan The User’s mental model • Object Orientation • CRC Cards • Lean and Agile The Programmer’s mental model • The Chasm between. Code and Execution • What the system IS – What the system DOES • Separation of concerns: Contexts with Roles • DCI: Data – Context – Interaction Defect removal • Lean: Get it right the first time • Chunkable, readable code. Baby. IDE. • Software Peer Review Conclusion UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 30

Edsger W. Dijkstra on Bugs "Program testing can be used to show the presence

Edsger W. Dijkstra on Bugs "Program testing can be used to show the presence of bugs, but never to show their absence!“ "Simplicity is prerequisite for reliability. “ UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 31

Peer Review Datamation Magazine ca. 1967 • • It’s hard to find bugs in

Peer Review Datamation Magazine ca. 1967 • • It’s hard to find bugs in own code It’s fun to find bugs in other people’s code Coder learns from reviewer’s comments Reviewer learns by reading the code Wikipedia: savings exceeds costs by 4 to 1". • Get it right the first time! • Test to confirm no blunder! --- but execute all statements Code must be Chunkable! Readable! UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 32

Code must be Chunkable! Readable! DCI Separation Of Concerns: • Data: Data classes greatly

Code must be Chunkable! Readable! DCI Separation Of Concerns: • Data: Data classes greatly simplified; realize ’pure’ data model. • Context: One Context for each use case, isolated from other Contexts. • Interaction: Roles only meaningful within their Context Role to object binding done within one chunk of methods. The Role Methods specify system behavior UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 33

Baby. IDE DCI Integrated Development Environment 2 1 3 UML-China 2010 4 © Trygve

Baby. IDE DCI Integrated Development Environment 2 1 3 UML-China 2010 4 © Trygve Reenskaug 2010 05. 12. 2020 34

Plan The User’s mental model • Object Orientation • CRC Cards • Lean and

Plan The User’s mental model • Object Orientation • CRC Cards • Lean and Agile The Programmer’s mental model • The Chasm between. Code and Execution • What the system IS – What the system DOES • Separation of concerns: Contexts with Roles • DCI: Data – Context – Interaction Defect removal • Lean: Get it right the first time • Chunkable, readable code. Baby. IDE. • Software Peer Review Conclusion UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 35

Conclusion – 1 of 4 DCI = Readable Code The DCI paradigm: Work with

Conclusion – 1 of 4 DCI = Readable Code The DCI paradigm: Work with program in different perspectives • D ata Classes for what the system IS • C • I UML-China 2010 ontext for the network of communicating roles nteraction for what the system DOES © Trygve Reenskaug 2010 05. 12. 2020 36

Conclusion – 2 of 4 DCI = Changeable Code • Data perspective compact; system

Conclusion – 2 of 4 DCI = Changeable Code • Data perspective compact; system state only. • Role/object selection separates system state and system behavior. • Existing Contexts can be changed independently. • New Contexts can be added to realize new funtionality. UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 37

Conclusion – 3 of 4 End User Mental Model = Code End User mental

Conclusion – 3 of 4 End User Mental Model = Code End User mental model domain model (what the system IS) use cases (what the system DOES) Runtime (objects play roles) instantiate data classes to objects context selects objects to play roles inject role methods Chasm Bridged! Compile time (Data, Context, Interaction) Object model code Programmer mental model UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 38

Conclusion – 4 of 4 State of DCI Implementation examples in Smalltalk/Squeak, C++, Java,

Conclusion – 4 of 4 State of DCI Implementation examples in Smalltalk/Squeak, C++, Java, C#, Ruby, Scala, Python. Real applications in Java (Qi 4 j, Rickard Øberg). New DCI Programming Language being developed. Baby. IDE Squeak Demo version available Basic technology is freely available for toolmakers For now: Read the “Lean Architecture” book Read Wikipedia article Never forget the end user of your code Never forget the reader of your code DCI Community at object-composition@googlegroups. com UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 39

Comments? Questions? UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 40

Comments? Questions? UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 40

More reading http: //www. ifi. uio. no/~trygver mailto: Coplien, J. O. , Bjørnvig, G;

More reading http: //www. ifi. uio. no/~trygver mailto: Coplien, J. O. , Bjørnvig, G; Lean Architecture for Agile Software Development; Wiley, Chichester, UK, 2010; ISBN 978 -0 -470 -68420 -7 Reenskaug, T; Wold, P. ; , Lehne, O. A. : Working With Objects; Manning, Greenwich, CT 06830; 1996; ISBN 1 -884777 -10 -4; (Prentice Hall ISBN 0 -13 -452930 -8). This book is out of print. An early. pdf version kan be downloaded free from [web page] http: //folk. uio. no/trygver/1996/book 11 d. pdf Important Web resources: Kay on object orientation: http: //gagne. homedns. org/~tgagne/contrib/Early. History. ST. html The DCI defining reference: http: //en. wikipedia. org/wiki/Data, _Context, _and_Interaction A technical article: http: //heim. ifi. uio. no/~trygver/2008/commonsense. pdf More online resources: http: //www. leansoftwarearchitecture. com/home/more-online-resources Reenskaug, T. : Programming with Roles and Classes; the Baby. UML Approach; Chapter in Klein, A. D. ; Computer Software Engineering Research; Nova Science Publishers, New York, 2007; ISBN-13: 978 -1 -60021 -774 -6; pp. 45 -88; [web page] http: //folk. uio. no/trygver/2007/baby. UML. pdf Reenskaug, T, : 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. [web page] http: //heim. ifi. uio. no/~trygver/2006/So. Sy. M/trygve. Discipline. pdf Wirfs-Brock, R. ; Mc. Kean, A. ; Object Design. Roles, Responsibilities, and Collaborations. ISBN 0‑ 201‑ 37943‑ 0; Addison-Wesley; Boston, MA, 2003. Andersen, E. P. ; Conceptual Modeling of Objects. A Role Modeling Approach. D. Scient thesis, November 1997, University of Oslo. [web page] http: //heim. ifi. uio. no/~trygver/1997/Egil. Andersen/Conceptual. Modeling. OO. pdf Gamma et. al. (GOF) Design Patterns; ISBN 0 -201 -63361 -; Addison-Wesley, Reading, MA. 1995. UML-China 2010 © Trygve Reenskaug 2010 05. 12. 2020 41