SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 30 day free trial to unlock unlimited reading.
Data Context Interaction is recently invented programming paradigm, which aims at separating behaviour from data model, by extracting interactions into roles, which can be played by objects in various contexts.
This presentation is going to give brief introduction to DCI, propose ways to implement roles' injection in Ruby and discuss how DCI could be used to supplement Rails' MVC paradigm.
Transcript
1.
DCI
Data Context Interaction
About me:
Dawid Sklodowski
Works at @HouseTrip (we are hiring)
2.
DCI: Why?
Separating behaviour from data model
Making behaviour first-class citizen
Supporting style of thinking closer to
people’s mental model
3.
DCI: Who?
Invented by Trygve Reenskaug
Current formulation mostly by Trygve
Reenskaug and Jim Coplien
In 2009
5.
Elf object would...
Reduce victim’s health points to 0.
Add some experience to itself.
Log frag on leader board.
Actually it should check who gets killed.
Or... maybe we should have fight before
deciding who dies.
6.
Lets leave the elf
object alone
He doesn’t need to know how killing is
implemented in system.
Lets implement activities (behaviours) for our
characters.
8.
Data
Data is “what system is”.
Objects which contain methods to change
their state.
No interaction with other objects
9.
Context
Entry point
Injects roles
Knows who does what
10.
Interaction
Interaction is “what system does”.
Implemented as roles which are played by
objects in run-time
11.
MVC and DCI
(how can it play with Rails)
DCI can be complementary to MVC
Controller loads adequate objects and
initiates context with them
Context injects roles to objects and let them
to play
12.
MVC and DCI
ControllerUser
Context
Model
View
Rolesdata object
15.
How to implement?
with Ruby
Problem: Role Injection
16.
How to implement
1. Decoration: #extend
Cons:
There is no
#unextend method
Tends to be slow
on some Rubies
17.
How to implement
2. Presenter
Pros:
Object encapsulation
Cons:
Object encapsulation
(however object still
accessible via
#object method)
18.
How to implement
3. Delegation
Cons:
Uses
#method_missing to
implement delegation
19.
How to implement
4. Delegate Class
It creates delegation methods for instance methods of delegated
class.
Cons:
Static delegation
relationship
Role is a class
instead of module
20.
How to implement
Dynamic DelegateClass
Dynamic delegation relationship, but isn’t that slow?
21.
How to implement
Any pattern can be implemented in dynamic way
Data Context Interaction is recently invented programming paradigm, which aims at separating behaviour from data model, by extracting interactions into roles, which can be played by objects in various contexts.
This presentation is going to give brief introduction to DCI, propose ways to implement roles' injection in Ruby and discuss how DCI could be used to supplement Rails' MVC paradigm.
Transcript
1.
DCI
Data Context Interaction
About me:
Dawid Sklodowski
Works at @HouseTrip (we are hiring)
2.
DCI: Why?
Separating behaviour from data model
Making behaviour first-class citizen
Supporting style of thinking closer to
people’s mental model
3.
DCI: Who?
Invented by Trygve Reenskaug
Current formulation mostly by Trygve
Reenskaug and Jim Coplien
In 2009
5.
Elf object would...
Reduce victim’s health points to 0.
Add some experience to itself.
Log frag on leader board.
Actually it should check who gets killed.
Or... maybe we should have fight before
deciding who dies.
6.
Lets leave the elf
object alone
He doesn’t need to know how killing is
implemented in system.
Lets implement activities (behaviours) for our
characters.
8.
Data
Data is “what system is”.
Objects which contain methods to change
their state.
No interaction with other objects
9.
Context
Entry point
Injects roles
Knows who does what
10.
Interaction
Interaction is “what system does”.
Implemented as roles which are played by
objects in run-time
11.
MVC and DCI
(how can it play with Rails)
DCI can be complementary to MVC
Controller loads adequate objects and
initiates context with them
Context injects roles to objects and let them
to play
12.
MVC and DCI
ControllerUser
Context
Model
View
Rolesdata object
15.
How to implement?
with Ruby
Problem: Role Injection
16.
How to implement
1. Decoration: #extend
Cons:
There is no
#unextend method
Tends to be slow
on some Rubies
17.
How to implement
2. Presenter
Pros:
Object encapsulation
Cons:
Object encapsulation
(however object still
accessible via
#object method)
18.
How to implement
3. Delegation
Cons:
Uses
#method_missing to
implement delegation
19.
How to implement
4. Delegate Class
It creates delegation methods for instance methods of delegated
class.
Cons:
Static delegation
relationship
Role is a class
instead of module
20.
How to implement
Dynamic DelegateClass
Dynamic delegation relationship, but isn’t that slow?
21.
How to implement
Any pattern can be implemented in dynamic way