SlideShare a Scribd company logo
DCI
- How to get ahead in software architecture
About me
Andreas Söderlund
Independent consultant in northern Sweden.
Worked on larger web systems and applications for 10-15 years, specializing in
system integration and architecture.
● E-commerce
● Banking
● Large-scale social platforms.
Haxe projects
Haxigniter, ufront, erazor, unject, umock, Haxedci, HaxeContracts
FORTRAN - IBM Mathematical Formula Translating System
COBOL - COmmon Business-Oriented Language
The roots of programming
"Formula translating", "Business-oriented"
Mapping from one language to another
"An explanation of someone's thought
process about how something works in
the real world."
Mental Models
"Lift the receiver and call the person you
want to reach by turning the circular
wheel."
Object terminology (receiver, wheel)
- with a function (call a person)
- based on a form (the phone).
"I need a container to get the wasp out."
Form & Function
The form enables the function
Mental Model Matching
When the mental model matches, the objects you control becomes an
extension of your mind.
It feels like you are directly manipulating the system.
Mental Model Matching...?
When the mental model mismatches, you lose control.
The programmers mental model mismatched the users.
Note: All unit tests passed in the software above!
The System
Objects with form... ...that can have different types of function
Mental models: Thought processes about the behavior of the above
Maybe all this can be called a system.
And the form of the system, its architecture?
"A set of interacting components forming an integrated whole"
Making a digital ordering
system for restaurants.
Designing a System
There must be a register with name and
birthdate of all employees.
Use when:
- Serving food
- Cooking food
- Customer pays bill
- Manager pays salary
class Employee
{
public var name : String;
public var birth : Date;
}
class Waiter extends Employee
{
}
class Chef extends Employee
{
}
class Manager extends Employee
{
}
class Employee
{
public var name : String;
public var birth : Date;
}
class Waiter extends Employee
{
}
class Chef extends Employee
{
}
class Manager extends Employee
{
}
"The waiter walks up to the guests and
shows them the menu. He takes the
order and passes it on to the chef. The
chef cooks the food, which is brought
out to the guests by the waiter.
After the meal the waiter brings the bill
to the guests, and collects the
payment."
The mental model of serving guests at
a Restaurant:
Designing a System
Part I
Inheritance
The Manager can also be a Chef and Waiter, if
the restaurant is small.
class Employee
{
public var name : String;
public var birth : Date;
public function serveFood() {}
public function cookFood() {}
public function bringBill() {}
}
class Waiter extends Employee
{
}
class Chef extends Employee
{
}
class Manager extends Employee
{
public function paySalaries() {}
}
I refuse to
deal with
customers!
I'm a great
waiter, but I
can't cook!
Part I.5: Multiple
Inheritance
The Manager can also be a Chef and Waiter, if
the restaurant is small.
class Employee
{
public var name : String;
public var birth : Date;
}
class Waiter extends Employee
{
public function serveFood() {}
public function bringBill() {}
}
class Chef extends Employee
{
public function cookFood() {}
}
class Manager extends Employee
{
public function paySalaries() {}
}
class ChefManager extends Chef extends Manager
{
}
class WaiterManager extends Waiter extends Manager
{
}
Not all Managers are both Chefs and Waiters of
course!
...what if even more employee types are
added?
...and how to instantiate this hierarchy?
Part II
Interfaces
class Employee
{
public var name : String;
public var birth : Date;
}
interface IChef
{
function cookFood() : Food;
}
interface IWait
{
function serveFood(f : Food) : Void;
function bringBill() : Money;
}
interface IManage
{
function paySalaries() : Void;
}
class Chef extends Employee implements IChef
{
public function cookFood() {}
}
class Waiter extends Employee implements IWait
{
public function serveFood(f : Food) {}
public function bringBill() {}
}
class Manager extends Employee implements IManage
{
public function paySalaries() {}
}
class ChefManager extends Manager implements IChef
{
public function cookFood() {}
}
class WaiterManager extends Manager ...
...
This is a beautiful architecture:
This code doesn’t have a beautiful form and
architecture.
Part II
Interfaces
class Employee
{
public var name : String;
public var birth : Date;
}
interface IChef
{
function cookFood() : Food;
}
interface IWait
{
function serveFood(f : Food) : Void;
function bringBill() : Money;
}
interface IManage
{
function paySalaries() : Void;
}
class Chef extends Employee implements IChef
{
public function cookFood() {}
}
class Waiter extends Employee implements IWait
{
public function serveFood(f : Food) {}
public function bringBill() {}
}
class Manager extends Employee implements IManage
{
public function paySalaries() {}
}
class ChefManager extends Manager implements IChef
{
public function cookFood() {}
}
class WaiterManager extends Manager ...
...
The code looks more like this:
Part II
Interfaces
The system form is not a representation of
the user mental model anymore (maybe
somewhere deep within), it's more and more
about engineering.
Want some Design Patterns with that?
- Abstract Factory
- Adapter
- Command
- Decorator
- Flyweight
- Memento
- Strategy
- Visitor
- ...
class Employee
{
public var name : String;
public var birth : Date;
}
interface IChef
{
function cookFood() : Food;
}
interface IWait
{
function serveFood(f : Food) : Void;
function bringBill() : Money;
}
interface IManage
{
function paySalaries() : Void;
}
class Chef extends Employee implements IChef
{
public function cookFood() {}
}
class Waiter extends Employee implements IWait
{
public function serveFood(f : Food) {}
public function bringBill() {}
}
class Manager extends Employee implements IManage
{
public function paySalaries() {}
}
class ChefManager extends Manager implements IChef
{
public function cookFood() {}
}
class WaiterManager extends Manager ...
...
Part II
Interfaces
class Employee
{
public var name : String;
public var birth : Date;
}
interface IChef
{
function cookFood() : Food;
}
interface IWait
{
function serveFood(f : Food) : Void;
function bringBill() : Money;
}
interface IManage
{
function paySalaries() : Void;
}
class Chef extends Employee implements IChef
{
public function cookFood() {}
}
class Waiter extends Employee implements IWait
{
public function serveFood(f : Food) {}
public function bringBill() {}
}
class Manager extends Employee implements IManage
{
public function paySalaries() {}
}
class ChefManager extends Manager implements IChef
{
public function cookFood() {}
}
class WaiterManager extends Manager ...
...
Want some Patterns with that?
- Abstract Factory
- Adapter
- Command
- Decorator
- Flyweight
- Lock
- Memento
- Strategy
- Visitor
- ...
Design patterns can be useful as implementation, but not as a user mental model and architecture.
However, there are patterns that are used to align a user mental model with the computer, like MVC.
This is an "indoor session initializer" because
there is a session that counts the number of bla
bla… (Nerd forcing mental model onto user)
Part III
Services
class Employee
{
public var name : String;
public var birth : Date;
}
interface IChefService
{
function cookFood(Employee e) : Food;
}
class ChefService implements IChefService
{
public Food cookFood(Employee e) { … }
}
// The program
static function main()
{
var chefService = Services.Get(IChefService);
var chef = Employee.Get(2);
chefService.cookFood(chef);
}
Object model mismatch. We move from “who
does what” to “what happens”. Too imperative
and all-knowing.
Information is abstracted away through
interfaces.
Part IV
DCI
Data, Context, Interaction
Inventors of DCI
Trygve Reenskaug
Inventor of MVC
Wrote CAD-software in the 60’s
Professor Emeritus, Oslo
James “Cope” Coplien
Author of several influential C++ books
Created most cited patent in software history
Chair CS 2003-2004, Brussels
Patterns, Scrum, Agile, Lean...
class Employee
{
public var name : String;
public var birth : Date;
}
● Chef - Cook food
● Waiter - Serve food, bring the bill
● Manager - Pay salary
Data
Function
class Employee
{
public var name : String;
public var birth : Date;
}
Data
Function
public function cookFood()
public function serveFood()
public function bringBill()
public function paySalaries()
Waiter
Waiter
Manager
Chef
If an Employee object
could attach the
cookFood() method...
then it could be a
Chef!
We cannot do it in classes (we tried in part I-
III), so it seems like it must be a more
dynamic operation.
class Employee
{
public var name : String;
public var birth : Date;
}
Data
Function
public function cookFood()
public function serveFood()
public function bringBill()
public function paySalaries()
Waiter
Waiter
Manager
Chef
Employee
object
public function
cookFood()
This Employee object can now play the Role of a Chef!
class Employee
{
public var name : String;
public var birth : Date;
}
Data Function
public function cookFood()
public function serveFood()
public function bringBill()
public function paySalaries()
Waiter
Waiter
Manager
Chef
Employee
object
public function
cookFood()
Now
a Chef
... a little later in
the program...
Same
Employee
object
public function cookFood()
{}
Later
a Manager
public function
paySalaries()
A Role is only relevant in a specific Context.
Roles and Contexts
A Mental Model can be represented as a Context!
Chef.cookFood()
vs.
Chef.cookFood()
Part IV
DCI
// Data (Form)
class Employee
{
public var name : String;
public var birth : Date;
}
"The waiter walks up to the guests and
shows them the menu. He takes the
order and passes it on to the chef. The
chef cooks the food, which is brought
out to the guests by the waiter.
After the meal the waiter brings the bill
to the guests, and collects the
payment."
The Context (Mental Model) of serving
guests at a Restaurant:
Part IV
DCI
// Data (Form)
class Employee
{
public var name : String;
public var birth : Date;
}
Remember from part I-III:
The methods cannot go in the data
class, they should be attached by some
means.
Where to put the methods, the
functionality?
Part IV
DCI
// Data (Form)
class Employee
{
public var name : String;
public var birth : Date;
}
// Context (Mental Model)
class ServeGuests implements haxedci.Context
{
@role var waiter = {}
@role var guests = {}
@role var chef = {}
}
"The waiter walks up to the guests and
shows them the menu. He takes the
order and passes it on to the chef. The
chef cooks the food, which is brought
out to the guests by the waiter.
After the meal the waiter brings the bill
to the guests, and collects the
payment."
The Context (Mental Model) of serving
guests at a Restaurant:
Guests ChefWaiter
guestsArriving()
selectFrom(menu)
takeOrder(order)
cook(order)
serve(food)
Part IV
DCI
"The waiter walks up to the guests and shows them the menu. He takes the order and passes it on
to the chef. The chef cooks the food, which is brought out to the guests by the waiter.
Part IV
DCI
The current “OO” way of
creating object communication:
Passing messages between
objects wherever and whenever
it is needed.
- Too chaotic
- No separation of data and behavior
- Can only see one object at a time
- Reasoning about system behavior
and functionality is very hard.
- Prevents object communication
- Creates a complex all-knowing
algorithm
- Basically a step back to Pascal
and Fortran.
Procedural thinking,
implemented as the
Mediator pattern.
- State and behavior is distributed
among the objects
- Creates a network of
collaborating objects
- We can reason about system
behavior at runtime!
DCI: A middle road,
distributed logic
under full control,
encapsulated in a
Context
Guests ChefWaiter
guestsArriving()
selectFrom(menu)
takeOrder(order)
cook(order)
serve(food)
Part IV
DCI
"The waiter walks up to the guests and shows them the menu. He takes the order and passes it on
to the chef. The chef cooks the food, which is brought out to the guests by the waiter.
Runtime
interaction!
Part IV
DCI
// Data (Form)
class Employee
{
public var name : String;
public var birth : Date;
}
// Context (Mental Model)
class ServeGuests implements haxedci.Context
{
@role var waiter = {}
@role var guests = {}
@role var chef = {}
public function new(employeeWaiter,
employeeChef,
guestList)
{
this.waiter = employeeWaiter;
this.chef = employeeChef;
this.guests = guestList;
}
"The waiter walks up to the guests and
shows them the menu. He takes the
order and passes it on to the chef. The
chef cooks the food, which is brought
out to the guests by the waiter.
After the meal the waiter brings the bill
to the guests, and collects the
payment."
The Context (Mental Model) of serving
guests at a Restaurant:
// System operation (Event)
public function guestsArriving()
{
waiter.guestsArriving();
}
}
Part IV
DCI
// Context (Mental Model)
class ServeGuests implements haxedci.Context
{
@role var waiter =
{
function guestsArriving() : Void
{
var menu = “1: Roast beef. 2: ...”;
guests.selectFrom(menu);
}
}
}
"The waiter walks up to the guests and
shows them the menu. He takes the
order and passes it on to the chef. The
chef cooks the food, which is brought
out to the guests by the waiter.
After the meal the waiter brings the bill
to the guests, and collects the
payment."
The Context (Mental Model) of serving
guests at a Restaurant:
Part IV
DCI
// Context (Mental Model)
class ServeGuests implements haxedci.Context
{
@role var waiter =
{
function guestsArriving() : Void
{
var menu = “1: Roast beef. 2: ...”;
guests.selectFrom(menu);
}
}
"The waiter walks up to the guests and
shows them the menu. He takes the
order and passes it on to the chef. The
chef cooks the food, which is brought
out to the guests by the waiter.
After the meal the waiter brings the bill
to the guests, and collects the
payment."
The Context (Mental Model) of serving
guests at a Restaurant:@role var guests =
{
function selectFrom(menu) : Void
{
Sys.println(menu);
order = Sys.stdin().readLine();
waiter.takeOrder(order);
}
}
}
Part IV
DCI
// Context (Mental Model)
class ServeGuests implements haxedci.Context
{
@role var waiter =
{
function guestsArriving() : Void
{
var menu = “1: Roast beef. 2: ...”;
guests.selectFrom(menu);
}
function takeOrder(order) : Void
{
Sys.println("Thank you.");
chef.cook(order);
}
}
"The waiter walks up to the guests and
shows them the menu. He takes the
order and passes it on to the chef. The
chef cooks the food, which is brought
out to the guests by the waiter.
After the meal the waiter brings the bill
to the guests, and collects the
payment."
The Context (Mental Model) of serving
guests at a Restaurant:
@role var guests =
{
function selectFrom(menu) : Void
{
Sys.println(menu);
var order = Sys.stdin().readLine();
waiter.takeOrder(order);
}
}
}
Part IV
DCI
// Data (Form)
class Employee
{
public var name : String;
public var birth : Date;
}
// Context (Mental Model)
class ServeGuests implements haxedci.Context
{
public function new(...)
{
this.waiter = employeeWaiter;
this.guests = listGuests;
this.chef = employeeChef;
}
"The waiter walks up to the guests and
shows them the menu. He takes the
order and passes it on to the chef. The
chef cooks the food, which is brought
out to the guests by the waiter.
After the meal the waiter brings the bill
to the guests, and collects the
payment."
The Context (Mental Model) of serving
guests at a Restaurant:
// System operation (Event)
public function guestsArriving()
{
waiter.guestsArriving();
}
// System operation (Event)
public function guestsPaying()
{
waiter.bringBill();
}
}
If "self" in the role doesn't reference
the object itself, it's not DCI.
// Data (Form)
class Employee
{
public var name : String;
public var birth : Date;
}
// Role
@role var waiter =
{
// RoleInterface
var roleInterface : {
var name : String;
}
// RoleMethods
function guestsArriving() : Void
{
Sys.println(self.name);
context.guests.selectFrom(menu);
}
...
}
Part IV
DCI
A DCI Role has a RoleInterface and
RoleMethods. The Role is private to its
Context.
The execution model for DCI is
different, adding new keywords: role
and context.
Object identity MUST be preserved!
(not equality, identity!)
The Employee Data (Form)
matches the RoleInterface, so
it can play the waiter Role.
Form matches the
RoleInterface for the
Role “container” in
the Context
“Remove Insect”
So what is DCI?
// Data (Form)
class Employee
{
public var name : String;
public var birth : Date;
}
// Context (Mental model/Use case/Algorithm)
class ServeGuests implements haxedci.Context
{
@role var waiter =
{
// RoleInterface (Compatible Form)
var roleInterface : {
var name : String;
}
// RoleMethods (Function)
function guestsArriving() : Void
{
var menu = new List<String>();
// Interaction (System behavior)
guests.selectFrom(menu);
}
}
// System operation (Events)
public function guestsArriving() : Void
{
waiter.guestsArriving();
}
}
A method of reflecting user mental
models in code.
A way of separating what the system IS
(Data, slowly changing) from what it DOES
(Function, quickly changing).
Allows reasoning about the correctness
of system functionality, not just
class/method functionality. We can
observe exactly what happens at
runtime. No Polymorphism.
Behavior is put back within the
boundaries of a human mental model,
not spread across classes, services,
patterns...
So what is DCI?
class Employee
{
public var name : String;
public var birth : Date;
}
class ServeGuests implements haxedci.Context
{
@role var waiter =
{
var roleInterface : {
var name : String;
}
function guestsArriving() : Void
{
var menu = new List<String>();
guests.selectFrom(menu);
}
}
public function guestsArriving() : Void
{
waiter.guestsArriving();
}
}
A method of reflecting user mental
models in code.
A way of separating what the system IS
(Data, slowly changing) from what it DOES
(Function, quickly changing).
Allows reasoning about the correctness
of system functionality, not just
class/method functionality. We can
observe exactly what happens at
runtime. No Polymorphism.
Behavior is put back within the
boundaries of a human mental model,
not spread across classes, services,
patterns...
Questions?
DCI Headquarters:
http://fulloo.info
Google “haxedci”
Thank you!
andreas@ivento.se
github.com/ciscoheat
google “haxedci”

More Related Content

PDF
Beginner’s tutorial (part 1) integrate redux form in react native application
PDF
Arista Networks - Building the Next Generation Workplace and Data Center Usin...
PPTX
Five myths about Network Function Virtualization (NFV)
PDF
OSS in the era of SDN and NFV: Evolution vs Revolution - What we can learn f...
PDF
The New Network for the Data Center
PDF
Alcatel-Lucent Cloud: Shaping the Future NFV OSS David Amzallag TM Forum 2013
PDF
Managing and Implementing Network Function Virtualization with Intelligent OSS
PDF
Data Center Interconnects: An Overview
Beginner’s tutorial (part 1) integrate redux form in react native application
Arista Networks - Building the Next Generation Workplace and Data Center Usin...
Five myths about Network Function Virtualization (NFV)
OSS in the era of SDN and NFV: Evolution vs Revolution - What we can learn f...
The New Network for the Data Center
Alcatel-Lucent Cloud: Shaping the Future NFV OSS David Amzallag TM Forum 2013
Managing and Implementing Network Function Virtualization with Intelligent OSS
Data Center Interconnects: An Overview

Viewers also liked (15)

PDF
How to adopt SDN/NFV Technology into the BSS & OSS stack and shorten the time...
PPTX
Container as a Service with Docker
PDF
06 - IDNOG04 - Dion Leung (Coriant) - Emerging Trends & Real Deployments for ...
PDF
PyParis2017 / Function-as-a-service - a pythonic perspective on severless com...
PDF
Serverless computing and Function-as-a-Service (FaaS)
PDF
Data Center Network Trends - Lin Nease
PDF
How will virtual networks, controlled by software, impact OSS systems?
PDF
Data center interconnect seamlessly through SDN
PPTX
Function as a Service: IT forum expo 2017
PDF
DCI - the architecture from the future
PDF
Managing change in the data center network
PPTX
Nexus 7000 Series Innovations: M3 Module, DCI, Scale
PPTX
Data center network reference architecture with hpe flex fabric
PDF
A Look Inside Google’s Data Center Networks
PDF
Summit 16: Open-O Mini-Summit - Orchestrating Network Connectivity Services
How to adopt SDN/NFV Technology into the BSS & OSS stack and shorten the time...
Container as a Service with Docker
06 - IDNOG04 - Dion Leung (Coriant) - Emerging Trends & Real Deployments for ...
PyParis2017 / Function-as-a-service - a pythonic perspective on severless com...
Serverless computing and Function-as-a-Service (FaaS)
Data Center Network Trends - Lin Nease
How will virtual networks, controlled by software, impact OSS systems?
Data center interconnect seamlessly through SDN
Function as a Service: IT forum expo 2017
DCI - the architecture from the future
Managing change in the data center network
Nexus 7000 Series Innovations: M3 Module, DCI, Scale
Data center network reference architecture with hpe flex fabric
A Look Inside Google’s Data Center Networks
Summit 16: Open-O Mini-Summit - Orchestrating Network Connectivity Services
Ad

Similar to Haxe dci-presentation by Andreas SÖDERLUND (20)

PDF
Jsf intro
PDF
Reviewing OOP Design patterns
PPT
JAX 08 - Agile RCP
PPTX
Decorator design pattern
PDF
OOP Is More Than Cars and Dogs
PDF
L2 Web App Development Guest Lecture At University of Surrey 20/11/09
PDF
Working With The Symfony Admin Generator
PDF
Pragmatic Functional Refactoring with Java 8
PDF
The Functional Programming Toolkit (NDC Oslo 2019)
PPT
Rcp by example
PPTX
Model View Presenter (MVP) In Aspnet
PPTX
Developing Android and iOS Apps With C#, .NET, Xamarin, Mono, and Windows Azure
PDF
Composable and streamable Play apps
KEY
Gwt and Xtend
PDF
Itjsf13
PDF
Itjsf13
PDF
ngMess: AngularJS Dependency Injection
PDF
Android DataBinding (ViewModel, UI Modularization and Testing)
PDF
computerscience-170129081612.pdf
KEY
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
Jsf intro
Reviewing OOP Design patterns
JAX 08 - Agile RCP
Decorator design pattern
OOP Is More Than Cars and Dogs
L2 Web App Development Guest Lecture At University of Surrey 20/11/09
Working With The Symfony Admin Generator
Pragmatic Functional Refactoring with Java 8
The Functional Programming Toolkit (NDC Oslo 2019)
Rcp by example
Model View Presenter (MVP) In Aspnet
Developing Android and iOS Apps With C#, .NET, Xamarin, Mono, and Windows Azure
Composable and streamable Play apps
Gwt and Xtend
Itjsf13
Itjsf13
ngMess: AngularJS Dependency Injection
Android DataBinding (ViewModel, UI Modularization and Testing)
computerscience-170129081612.pdf
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
Ad

More from Grégory PARODI (9)

PDF
Template slide for SILEX
PDF
san fransisco
PDF
PDF
PDF
Bigpics 1
PDF
thaillande
Template slide for SILEX
san fransisco
Bigpics 1
thaillande

Recently uploaded (20)

PPTX
introduction about ICD -10 & ICD-11 ppt.pptx
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PPTX
Introduction to Information and Communication Technology
PPTX
Introuction about WHO-FIC in ICD-10.pptx
PPTX
Funds Management Learning Material for Beg
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
PDF
The Internet -By the Numbers, Sri Lanka Edition
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PDF
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
PPTX
QR Codes Qr codecodecodecodecocodedecodecode
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PDF
Testing WebRTC applications at scale.pdf
PPTX
artificial intelligence overview of it and more
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
PPTX
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
introduction about ICD -10 & ICD-11 ppt.pptx
522797556-Unit-2-Temperature-measurement-1-1.pptx
Introduction to Information and Communication Technology
Introuction about WHO-FIC in ICD-10.pptx
Funds Management Learning Material for Beg
Decoding a Decade: 10 Years of Applied CTI Discipline
An introduction to the IFRS (ISSB) Stndards.pdf
The Internet -By the Numbers, Sri Lanka Edition
WebRTC in SignalWire - troubleshooting media negotiation
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
QR Codes Qr codecodecodecodecocodedecodecode
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
Cloud-Scale Log Monitoring _ Datadog.pdf
Slides PDF The World Game (s) Eco Economic Epochs.pdf
Testing WebRTC applications at scale.pdf
artificial intelligence overview of it and more
The New Creative Director: How AI Tools for Social Media Content Creation Are...
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
Unit-1 introduction to cyber security discuss about how to secure a system
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...

Haxe dci-presentation by Andreas SÖDERLUND

  • 1. DCI - How to get ahead in software architecture
  • 2. About me Andreas Söderlund Independent consultant in northern Sweden. Worked on larger web systems and applications for 10-15 years, specializing in system integration and architecture. ● E-commerce ● Banking ● Large-scale social platforms. Haxe projects Haxigniter, ufront, erazor, unject, umock, Haxedci, HaxeContracts
  • 3. FORTRAN - IBM Mathematical Formula Translating System COBOL - COmmon Business-Oriented Language The roots of programming "Formula translating", "Business-oriented" Mapping from one language to another
  • 4. "An explanation of someone's thought process about how something works in the real world." Mental Models "Lift the receiver and call the person you want to reach by turning the circular wheel." Object terminology (receiver, wheel) - with a function (call a person) - based on a form (the phone).
  • 5. "I need a container to get the wasp out." Form & Function The form enables the function
  • 6. Mental Model Matching When the mental model matches, the objects you control becomes an extension of your mind. It feels like you are directly manipulating the system.
  • 7. Mental Model Matching...? When the mental model mismatches, you lose control. The programmers mental model mismatched the users. Note: All unit tests passed in the software above!
  • 8. The System Objects with form... ...that can have different types of function Mental models: Thought processes about the behavior of the above Maybe all this can be called a system. And the form of the system, its architecture? "A set of interacting components forming an integrated whole"
  • 9. Making a digital ordering system for restaurants. Designing a System There must be a register with name and birthdate of all employees. Use when: - Serving food - Cooking food - Customer pays bill - Manager pays salary class Employee { public var name : String; public var birth : Date; } class Waiter extends Employee { } class Chef extends Employee { } class Manager extends Employee { }
  • 10. class Employee { public var name : String; public var birth : Date; } class Waiter extends Employee { } class Chef extends Employee { } class Manager extends Employee { } "The waiter walks up to the guests and shows them the menu. He takes the order and passes it on to the chef. The chef cooks the food, which is brought out to the guests by the waiter. After the meal the waiter brings the bill to the guests, and collects the payment." The mental model of serving guests at a Restaurant: Designing a System
  • 11. Part I Inheritance The Manager can also be a Chef and Waiter, if the restaurant is small. class Employee { public var name : String; public var birth : Date; public function serveFood() {} public function cookFood() {} public function bringBill() {} } class Waiter extends Employee { } class Chef extends Employee { } class Manager extends Employee { public function paySalaries() {} } I refuse to deal with customers! I'm a great waiter, but I can't cook!
  • 12. Part I.5: Multiple Inheritance The Manager can also be a Chef and Waiter, if the restaurant is small. class Employee { public var name : String; public var birth : Date; } class Waiter extends Employee { public function serveFood() {} public function bringBill() {} } class Chef extends Employee { public function cookFood() {} } class Manager extends Employee { public function paySalaries() {} } class ChefManager extends Chef extends Manager { } class WaiterManager extends Waiter extends Manager { } Not all Managers are both Chefs and Waiters of course! ...what if even more employee types are added? ...and how to instantiate this hierarchy?
  • 13. Part II Interfaces class Employee { public var name : String; public var birth : Date; } interface IChef { function cookFood() : Food; } interface IWait { function serveFood(f : Food) : Void; function bringBill() : Money; } interface IManage { function paySalaries() : Void; } class Chef extends Employee implements IChef { public function cookFood() {} } class Waiter extends Employee implements IWait { public function serveFood(f : Food) {} public function bringBill() {} } class Manager extends Employee implements IManage { public function paySalaries() {} } class ChefManager extends Manager implements IChef { public function cookFood() {} } class WaiterManager extends Manager ... ... This is a beautiful architecture: This code doesn’t have a beautiful form and architecture.
  • 14. Part II Interfaces class Employee { public var name : String; public var birth : Date; } interface IChef { function cookFood() : Food; } interface IWait { function serveFood(f : Food) : Void; function bringBill() : Money; } interface IManage { function paySalaries() : Void; } class Chef extends Employee implements IChef { public function cookFood() {} } class Waiter extends Employee implements IWait { public function serveFood(f : Food) {} public function bringBill() {} } class Manager extends Employee implements IManage { public function paySalaries() {} } class ChefManager extends Manager implements IChef { public function cookFood() {} } class WaiterManager extends Manager ... ... The code looks more like this:
  • 15. Part II Interfaces The system form is not a representation of the user mental model anymore (maybe somewhere deep within), it's more and more about engineering. Want some Design Patterns with that? - Abstract Factory - Adapter - Command - Decorator - Flyweight - Memento - Strategy - Visitor - ... class Employee { public var name : String; public var birth : Date; } interface IChef { function cookFood() : Food; } interface IWait { function serveFood(f : Food) : Void; function bringBill() : Money; } interface IManage { function paySalaries() : Void; } class Chef extends Employee implements IChef { public function cookFood() {} } class Waiter extends Employee implements IWait { public function serveFood(f : Food) {} public function bringBill() {} } class Manager extends Employee implements IManage { public function paySalaries() {} } class ChefManager extends Manager implements IChef { public function cookFood() {} } class WaiterManager extends Manager ... ...
  • 16. Part II Interfaces class Employee { public var name : String; public var birth : Date; } interface IChef { function cookFood() : Food; } interface IWait { function serveFood(f : Food) : Void; function bringBill() : Money; } interface IManage { function paySalaries() : Void; } class Chef extends Employee implements IChef { public function cookFood() {} } class Waiter extends Employee implements IWait { public function serveFood(f : Food) {} public function bringBill() {} } class Manager extends Employee implements IManage { public function paySalaries() {} } class ChefManager extends Manager implements IChef { public function cookFood() {} } class WaiterManager extends Manager ... ... Want some Patterns with that? - Abstract Factory - Adapter - Command - Decorator - Flyweight - Lock - Memento - Strategy - Visitor - ... Design patterns can be useful as implementation, but not as a user mental model and architecture. However, there are patterns that are used to align a user mental model with the computer, like MVC. This is an "indoor session initializer" because there is a session that counts the number of bla bla… (Nerd forcing mental model onto user)
  • 17. Part III Services class Employee { public var name : String; public var birth : Date; } interface IChefService { function cookFood(Employee e) : Food; } class ChefService implements IChefService { public Food cookFood(Employee e) { … } } // The program static function main() { var chefService = Services.Get(IChefService); var chef = Employee.Get(2); chefService.cookFood(chef); } Object model mismatch. We move from “who does what” to “what happens”. Too imperative and all-knowing. Information is abstracted away through interfaces.
  • 19. Inventors of DCI Trygve Reenskaug Inventor of MVC Wrote CAD-software in the 60’s Professor Emeritus, Oslo James “Cope” Coplien Author of several influential C++ books Created most cited patent in software history Chair CS 2003-2004, Brussels Patterns, Scrum, Agile, Lean...
  • 20. class Employee { public var name : String; public var birth : Date; } ● Chef - Cook food ● Waiter - Serve food, bring the bill ● Manager - Pay salary Data Function
  • 21. class Employee { public var name : String; public var birth : Date; } Data Function public function cookFood() public function serveFood() public function bringBill() public function paySalaries() Waiter Waiter Manager Chef If an Employee object could attach the cookFood() method... then it could be a Chef! We cannot do it in classes (we tried in part I- III), so it seems like it must be a more dynamic operation.
  • 22. class Employee { public var name : String; public var birth : Date; } Data Function public function cookFood() public function serveFood() public function bringBill() public function paySalaries() Waiter Waiter Manager Chef Employee object public function cookFood() This Employee object can now play the Role of a Chef!
  • 23. class Employee { public var name : String; public var birth : Date; } Data Function public function cookFood() public function serveFood() public function bringBill() public function paySalaries() Waiter Waiter Manager Chef Employee object public function cookFood() Now a Chef ... a little later in the program... Same Employee object public function cookFood() {} Later a Manager public function paySalaries()
  • 24. A Role is only relevant in a specific Context. Roles and Contexts A Mental Model can be represented as a Context! Chef.cookFood() vs. Chef.cookFood()
  • 25. Part IV DCI // Data (Form) class Employee { public var name : String; public var birth : Date; } "The waiter walks up to the guests and shows them the menu. He takes the order and passes it on to the chef. The chef cooks the food, which is brought out to the guests by the waiter. After the meal the waiter brings the bill to the guests, and collects the payment." The Context (Mental Model) of serving guests at a Restaurant:
  • 26. Part IV DCI // Data (Form) class Employee { public var name : String; public var birth : Date; } Remember from part I-III: The methods cannot go in the data class, they should be attached by some means. Where to put the methods, the functionality?
  • 27. Part IV DCI // Data (Form) class Employee { public var name : String; public var birth : Date; } // Context (Mental Model) class ServeGuests implements haxedci.Context { @role var waiter = {} @role var guests = {} @role var chef = {} } "The waiter walks up to the guests and shows them the menu. He takes the order and passes it on to the chef. The chef cooks the food, which is brought out to the guests by the waiter. After the meal the waiter brings the bill to the guests, and collects the payment." The Context (Mental Model) of serving guests at a Restaurant:
  • 28. Guests ChefWaiter guestsArriving() selectFrom(menu) takeOrder(order) cook(order) serve(food) Part IV DCI "The waiter walks up to the guests and shows them the menu. He takes the order and passes it on to the chef. The chef cooks the food, which is brought out to the guests by the waiter.
  • 29. Part IV DCI The current “OO” way of creating object communication: Passing messages between objects wherever and whenever it is needed. - Too chaotic - No separation of data and behavior - Can only see one object at a time - Reasoning about system behavior and functionality is very hard. - Prevents object communication - Creates a complex all-knowing algorithm - Basically a step back to Pascal and Fortran. Procedural thinking, implemented as the Mediator pattern. - State and behavior is distributed among the objects - Creates a network of collaborating objects - We can reason about system behavior at runtime! DCI: A middle road, distributed logic under full control, encapsulated in a Context
  • 30. Guests ChefWaiter guestsArriving() selectFrom(menu) takeOrder(order) cook(order) serve(food) Part IV DCI "The waiter walks up to the guests and shows them the menu. He takes the order and passes it on to the chef. The chef cooks the food, which is brought out to the guests by the waiter. Runtime interaction!
  • 31. Part IV DCI // Data (Form) class Employee { public var name : String; public var birth : Date; } // Context (Mental Model) class ServeGuests implements haxedci.Context { @role var waiter = {} @role var guests = {} @role var chef = {} public function new(employeeWaiter, employeeChef, guestList) { this.waiter = employeeWaiter; this.chef = employeeChef; this.guests = guestList; } "The waiter walks up to the guests and shows them the menu. He takes the order and passes it on to the chef. The chef cooks the food, which is brought out to the guests by the waiter. After the meal the waiter brings the bill to the guests, and collects the payment." The Context (Mental Model) of serving guests at a Restaurant: // System operation (Event) public function guestsArriving() { waiter.guestsArriving(); } }
  • 32. Part IV DCI // Context (Mental Model) class ServeGuests implements haxedci.Context { @role var waiter = { function guestsArriving() : Void { var menu = “1: Roast beef. 2: ...”; guests.selectFrom(menu); } } } "The waiter walks up to the guests and shows them the menu. He takes the order and passes it on to the chef. The chef cooks the food, which is brought out to the guests by the waiter. After the meal the waiter brings the bill to the guests, and collects the payment." The Context (Mental Model) of serving guests at a Restaurant:
  • 33. Part IV DCI // Context (Mental Model) class ServeGuests implements haxedci.Context { @role var waiter = { function guestsArriving() : Void { var menu = “1: Roast beef. 2: ...”; guests.selectFrom(menu); } } "The waiter walks up to the guests and shows them the menu. He takes the order and passes it on to the chef. The chef cooks the food, which is brought out to the guests by the waiter. After the meal the waiter brings the bill to the guests, and collects the payment." The Context (Mental Model) of serving guests at a Restaurant:@role var guests = { function selectFrom(menu) : Void { Sys.println(menu); order = Sys.stdin().readLine(); waiter.takeOrder(order); } } }
  • 34. Part IV DCI // Context (Mental Model) class ServeGuests implements haxedci.Context { @role var waiter = { function guestsArriving() : Void { var menu = “1: Roast beef. 2: ...”; guests.selectFrom(menu); } function takeOrder(order) : Void { Sys.println("Thank you."); chef.cook(order); } } "The waiter walks up to the guests and shows them the menu. He takes the order and passes it on to the chef. The chef cooks the food, which is brought out to the guests by the waiter. After the meal the waiter brings the bill to the guests, and collects the payment." The Context (Mental Model) of serving guests at a Restaurant: @role var guests = { function selectFrom(menu) : Void { Sys.println(menu); var order = Sys.stdin().readLine(); waiter.takeOrder(order); } } }
  • 35. Part IV DCI // Data (Form) class Employee { public var name : String; public var birth : Date; } // Context (Mental Model) class ServeGuests implements haxedci.Context { public function new(...) { this.waiter = employeeWaiter; this.guests = listGuests; this.chef = employeeChef; } "The waiter walks up to the guests and shows them the menu. He takes the order and passes it on to the chef. The chef cooks the food, which is brought out to the guests by the waiter. After the meal the waiter brings the bill to the guests, and collects the payment." The Context (Mental Model) of serving guests at a Restaurant: // System operation (Event) public function guestsArriving() { waiter.guestsArriving(); } // System operation (Event) public function guestsPaying() { waiter.bringBill(); } }
  • 36. If "self" in the role doesn't reference the object itself, it's not DCI. // Data (Form) class Employee { public var name : String; public var birth : Date; } // Role @role var waiter = { // RoleInterface var roleInterface : { var name : String; } // RoleMethods function guestsArriving() : Void { Sys.println(self.name); context.guests.selectFrom(menu); } ... } Part IV DCI A DCI Role has a RoleInterface and RoleMethods. The Role is private to its Context. The execution model for DCI is different, adding new keywords: role and context. Object identity MUST be preserved! (not equality, identity!) The Employee Data (Form) matches the RoleInterface, so it can play the waiter Role. Form matches the RoleInterface for the Role “container” in the Context “Remove Insect”
  • 37. So what is DCI? // Data (Form) class Employee { public var name : String; public var birth : Date; } // Context (Mental model/Use case/Algorithm) class ServeGuests implements haxedci.Context { @role var waiter = { // RoleInterface (Compatible Form) var roleInterface : { var name : String; } // RoleMethods (Function) function guestsArriving() : Void { var menu = new List<String>(); // Interaction (System behavior) guests.selectFrom(menu); } } // System operation (Events) public function guestsArriving() : Void { waiter.guestsArriving(); } } A method of reflecting user mental models in code. A way of separating what the system IS (Data, slowly changing) from what it DOES (Function, quickly changing). Allows reasoning about the correctness of system functionality, not just class/method functionality. We can observe exactly what happens at runtime. No Polymorphism. Behavior is put back within the boundaries of a human mental model, not spread across classes, services, patterns...
  • 38. So what is DCI? class Employee { public var name : String; public var birth : Date; } class ServeGuests implements haxedci.Context { @role var waiter = { var roleInterface : { var name : String; } function guestsArriving() : Void { var menu = new List<String>(); guests.selectFrom(menu); } } public function guestsArriving() : Void { waiter.guestsArriving(); } } A method of reflecting user mental models in code. A way of separating what the system IS (Data, slowly changing) from what it DOES (Function, quickly changing). Allows reasoning about the correctness of system functionality, not just class/method functionality. We can observe exactly what happens at runtime. No Polymorphism. Behavior is put back within the boundaries of a human mental model, not spread across classes, services, patterns...