Contexts are Roles when you look at them from outside, and Roles are Contexts when you look at them from inside?

161 views
Skip to first unread message

Oleh Novosad

unread,
Feb 26, 2019, 2:09:06 AM2/26/19
to object-composition

What bothered me is that both roles and contexts are code. I couldn't fully wrap my mind around these concepts, something felt too asymmetrical :) but I think, I finally figured it out unless I am wrong:


Contexts are actually Roles but Roles when you look at them from outside. 
Roles are Contexts but when you look at them from inside.

This means that, for example, in MVC, M, V, C - are both roles from outside and contexts from inside. For example, many black boxes (objects) can play the role of Controller, but inside of this role, Controller is actually Context that has a script for Models and Views roles.

I think maybe this is how DCI can work in a fractal way - Contexts are Roles for higher level Contexts which are Roles for higher level Contexts etc.

James O Coplien

unread,
Feb 26, 2019, 5:06:41 AM2/26/19
to object-co...@googlegroups.com
Contexts can play Roles. Contexts are not Roles.

--
You received this message because you are subscribed to the Google Groups "object-composition" group.
To unsubscribe from this group and stop receiving emails from it, send an email to object-composit...@googlegroups.com.
To post to this group, send email to object-co...@googlegroups.com.
Visit this group at https://groups.google.com/group/object-composition.
For more options, visit https://groups.google.com/d/optout.

Rune Funch Søltoft

unread,
Feb 26, 2019, 5:13:02 AM2/26/19
to object-co...@googlegroups.com
A context is an object a role is not. An object can play a role (if it can fulfil the role contract). Such an object is called a roleplayer. It’s not uncommon for a context to play a role (at least not in my code)

Mvh
Rune

Oleh Novosad

unread,
Feb 26, 2019, 12:11:25 PM2/26/19
to object-composition
I am not sure Contexts are necessary objects/instances - this is just how it was chosen to implement contexts in specific languages. Context is just a script or set of scripts (use-cases) where instances play roles.

But what is Role? Role is also a set of scripts for an instance to play. But because instance/object is a collection of other instances/objects and because Role is supposed to use other Roles in its' implementation from inside Role is Context.

Example:

Dancer is a role that can be played by human instances in Theatre.
Dancer role has scripts that use Hand role, Leg role, Torse role, Head role etc. to do moves.
Theatre is a Context inside of which Dancers dance. 
Theatre context has play_show() method in which human instances play Dancer roles and dance.
City is a context where building instances play their roles.
Theatre is also a role for building instance. Some building instances play Theatre role, some are not.
City is a role for instances of big groups of buildings. Instances of big groups of buildings can play different roles: like City and Village.
Country is a context .....etc.


Rune Funch Søltoft

unread,
Feb 26, 2019, 12:26:05 PM2/26/19
to object-co...@googlegroups.com


Den 26. feb. 2019 kl. 18.11 skrev Oleh Novosad <oleh.n...@gmail.com>:

I am not sure Contexts are necessary objects/instances

I am. From Trygve and Cope’s definition of a context found at fulloo.info

Code in the Context perspective specifies runtime networks of interconnected objects
(Emphasis mine)

Oleh Novosad

unread,
Feb 26, 2019, 12:44:48 PM2/26/19
to object-composition
Code in the Context perspective specifies runtime networks of interconnected objects
(Emphasis mine)

"Runtime networks of interconnected objects" happen when the script is executed. 
It doesn't contradict with what I am saying because if Context is Role in higher level Context, in order to be executed it has to be assigned to an instance.

It is a bit hard to explain, but it doesn't contradict with what I am saying.

rune funch

unread,
Feb 26, 2019, 1:38:19 PM2/26/19
to object-co...@googlegroups.com
I don't understand. You said: "I am not sure Contexts are necessary objects/instances - this is just how it was chosen to implement contexts in specific languages" and I simply replied that by definition contexts are objects and a context can't be a role but it can be a roleplayer in a higher level context

--

Matthew Browne

unread,
Feb 26, 2019, 1:39:56 PM2/26/19
to object-co...@googlegroups.com
Oleh, perhaps you could share some code to demonstrate your concept? I find that when writing DCI code in practice, it becomes pretty clear how Contexts are objects that may or may not play roles in other Contexts.

For example, many black boxes (objects) can play the role of Controller, but inside of this role, Controller is actually Context that has a script for Models and Views roles.

I think you are on to something with this part. The whole purpose of the Controller is to facilitate interaction between the Model and the Views, so I agree that Controllers should (or at least could) be Contexts.

--

Oleh Novosad

unread,
Feb 26, 2019, 1:50:15 PM2/26/19
to object-composition


I don't understand. You said: "I am not sure Contexts are necessary objects/instances - this is just how it was chosen to implement contexts in specific languages" and I simply replied that by definition contexts are objects and a context can't be a role but it can be a roleplayer in a higher level context

 "can be a roleplayer in a higher level context"

Yes, this is what I mean when I say that "context is role when looking from outside".

Rune Funch Søltoft

unread,
Feb 26, 2019, 1:59:56 PM2/26/19
to object-co...@googlegroups.com

> Den 26. feb. 2019 kl. 19.50 skrev Oleh Novosad <oleh.n...@gmail.com>:
>
> Yes, this is what I mean when I say that "context is role when looking from outside".

To avoid confusion I would advice to using standard terminology. A role is played by a roleplayer. A context can be a roleplayer but not a role

Oleh Novosad

unread,
Feb 26, 2019, 2:03:58 PM2/26/19
to object-composition


To avoid confusion I would advice to using standard terminology. A role is played by a roleplayer. A context can be a roleplayer but not a role

Are you saying that I cannot assign Theatre role to other buildings?

Matthew Browne

unread,
Feb 26, 2019, 4:07:21 PM2/26/19
to object-composition
I wonder if part of the confusion here is due to not distinguishing between a Context declaration and a Context instance? e.g. for the Context declaration 'Dog' ('context Dog {...}'), there might be Context instances 'fido', 'fluffy', 'clifford', etc.

In traditional OOP we would differentiate between the "Dog class" and "Dog instances". In DCI I feel like we don't currently have the best terminology for this, and we use the same term 'context' in both ways.

Having said that, the distinction between role and role player is probably the most relevant thing here.

Rune Funch Søltoft

unread,
Feb 26, 2019, 4:08:36 PM2/26/19
to object-co...@googlegroups.com

> Den 26. feb. 2019 kl. 20.03 skrev Oleh Novosad <oleh.n...@gmail.com>:
>
> Are you saying that I cannot assign Theatre role to other buildings?
No I’m saying it difficult to understand what you are trying to say. If you don’t use the common terminology. Eg you assign an object to play a role. That makes said object a roleplayer.
A role is not an object.

James O Coplien

unread,
Feb 26, 2019, 4:40:07 PM2/26/19
to object-co...@googlegroups.com
I can see your perspective.

James O Coplien

unread,
Feb 26, 2019, 4:41:32 PM2/26/19
to object-co...@googlegroups.com


On 26 Feb 2019, at 19.50, Oleh Novosad <oleh.n...@gmail.com> wrote:

 "can be a roleplayer in a higher level context"

Yes, this is what I mean when I say that "context is role when looking from outside".

“Can be” and “is” are not the same. As I said at the beginning: a Context instance can be a Role-player. But not all Context instances are Role-players.

James O Coplien

unread,
Feb 26, 2019, 4:42:30 PM2/26/19
to object-co...@googlegroups.com


On 26 Feb 2019, at 20.03, Oleh Novosad <oleh.n...@gmail.com> wrote:

Are you saying that I cannot assign Theatre role to other buildings?

Try restating this more precisely. “Assign” is not DCI-ese.

Oleh Novosad

unread,
Feb 26, 2019, 4:48:34 PM2/26/19
to object-composition


Try restating this more precisely. “Assign” is not DCI-ese.

"Are you saying that other buildings cannot play Theatre role?" 
Is this more correct?


Oleh Novosad

unread,
Feb 26, 2019, 4:52:49 PM2/26/19
to object-composition

I think, my point is that Theatre is Context for humans/instances to play Dancer role.
But at the same time Theatre is Role for buildings to play Theatre.

Rune Funch Søltoft

unread,
Feb 26, 2019, 5:31:45 PM2/26/19
to object-co...@googlegroups.com
I would argue that the context isn’t the Theater building but that there’s a play-context that has several roles and that play-context plays a play role in the Theater context where “my house” (or another more suitable building) plays the role of venue

Mvh
Rune

Den 26. feb. 2019 kl. 22.52 skrev Oleh Novosad <oleh.n...@gmail.com>:


I think, my point is that Theatre is Context for humans/instances to play Dancer role.
But at the same time Theatre is Role for buildings to play Theatre.

--

Oleh Novosad

unread,
Feb 26, 2019, 6:06:03 PM2/26/19
to object-composition
I would argue that the context isn’t the Theater building but that there’s a play-context that has several roles and that play-context plays a play role in the Theater context where “my house” (or another more suitable building) plays the role of venue

Is there a way I can help you to understand what I am trying to say?

James O Coplien

unread,
Feb 27, 2019, 5:13:44 AM2/27/19
to object-co...@googlegroups.com


On 27 Feb 2019, at 00.06, Oleh Novosad <oleh.n...@gmail.com> wrote:

Is there a way I can help you to understand what I am trying to say?

Example code. I think someone else already made this suggestion, too.

Trygve Reenskaug

unread,
Feb 27, 2019, 10:37:04 AM2/27/19
to object-co...@googlegroups.com
On 27.02.2019 00:06, Oleh Novosad wrote:
I would argue that the context isn’t the Theater building but that there’s a play-context that has several roles and that play-context plays a play role in the Theater context where “my house” (or another more suitable building) plays the role of venue

Is there a way I can help you to understand what I am trying to say?

Hi Oleh,
not having followed this thread, I can only take your words on their face value. You asked for it and here is my brutal advice:
    Express your thoughts using well-defined words in a clear syntax.

Note that I do not say anything about the quality of your thoughts, not even about your ability to express them.  I only criticize the way you have expressed them in the above quote.

I see four dozen fuzzy words with arbitrary capitalization, no punctuation and not even a single line shift. I have spent a good deal of effort and good-will trying to decode them. I have used my understanding of DCI, COPE's syntax for his trygve language, and my own convention of writing role names in all caps to create my interpretation. It may or may not be what you intended:
context PlayContext {
    role CLAUDIUS {} // played by a human actor
    role HAMLET {} // played by a human actor
     ...
    }
context TheatreContext {
    role VENUE {} // played by some building such as "my house"
    role PERFORMANCE {} // played by an instance of PlayContext
    ...
    }
the point seems to be that a Context can play a role in another Context.

Enjoy
--Trygve

 

Message has been deleted

Oleh Novosad

unread,
Feb 27, 2019, 11:56:59 AM2/27/19
to object-composition


I would argue that the context isn’t the Theater building but that there’s a play-context that has several roles and that play-context plays a play role in the Theater context where “my house” (or another more suitable building) plays the role of venue

Trygve, thank you, above text is not mine, Rune is trying to confuse everyone? :). 

This example is in pseudo-DCI-language
Symbol '#' marks the start of a comment.


##############################################################################
# This example shows pretty normal way of doint things

# Role definition
role DANCER 
# dance method
def dance()
#...
end 
end 

context Theater 
# play show in theatre 
def play_show(dancer as DANCER)
dancer.dance()
end 
end 

# Create human instance/object
bob = Human.new 

# Create Theatre instance, check if bob can play DANCER role and pass it to play_show() script, 
# execute play_show() script
Theather.new.play_show(bob as DANCER)

##############################################################################
# This example shows how context could be not an object, 
# everything else is pretty standard 

# Role definition
role DANCER 
# dance method
def dance()
#...
end 
end 

context Theater 
# static/class method of Theather context
def self.play_show(dancer as DANCER)
dancer.dance()
end 
end 

# create human instance
bob = Human.new 

# here we call static/class method of Theatre
Theather.play_show(bob as DANCER)


##############################################################################
# This example shows how previously Theatre context could be transformed into role

# Role definition
role DANCER 
# dance method
def dance()
#...
end 
end 

role THEATHER 
# play show in theatre 
def play_show(dancer as DANCER)
dancer.dance()
end 
end 

# create human instance
bob = Human.new 
# create building instance
building = Building.new


(building as THEATHER).play_show(bob as DANCER)

##############################################################################
# Same as above but dancer being "inside" of building

# Role definition
role DANCER 
# dance method
def dance()
#...
end 
end 

role THEATHER 
dancer as DANCER 

# play show in theatre 
def play_show()
dancer.dance()
end 
end 

# create human instance
bob = Human.new 
# create building instance
building = Building.new(dancer: bob)

# budiling plays theatre role and execute show
(building as THEATHER).play_show()

If roles can replace contexts (or be like context)  in OOP, do we need contexts at all? 

Trygve Reenskaug

unread,
Feb 27, 2019, 12:10:07 PM2/27/19
to object-co...@googlegroups.com
Good for you!
--
You received this message because you are subscribed to the Google Groups "object-composition" group.
To unsubscribe from this group and stop receiving emails from it, send an email to object-composit...@googlegroups.com.
To post to this group, send email to object-co...@googlegroups.com.
Visit this group at https://groups.google.com/group/object-composition.
For more options, visit https://groups.google.com/d/optout.

--

The essence of object orientation is that objects collaborate  to achieve a goal.
Trygve Reenskaug      
mailto: try...@ifi.uio.no
Morgedalsvn. 5A       
http://folk.uio.no/trygver/
N-0378 Oslo             
http://fullOO.info
Norway                     Tel: (+47) 22 49 57 27

Rune Funch Søltoft

unread,
Feb 27, 2019, 12:38:40 PM2/27/19
to object-co...@googlegroups.com
Alan Kay defines OO systems as a network of interconnected systems. The definition is recursive. Each system is an object that itself might be a network of interconnected objects. It is this view of OO that DCI can express. Each context is a node in the network of interconnected objects. Within a context the expectations and (potential) contributions of each node is expressed using roles. A role is something that lives inside a specific context and has no meaning outside of a context. This makes it different from an interface, mixin etc. 

So you might have a context with a role Theater. That can be played by a subset of all buildings. In that context your might also have a play role that can be played by a context representing the concrete play eg Hamlet or Erasmus Montanus. 
Each context would have their own network of interconnected objects such as characters and stage props. In a specific context instance all roleplayers are bound to their individual roles in one atomic operation.

Oleh Novosad

unread,
Feb 28, 2019, 1:24:43 PM2/28/19
to object-composition
the point seems to be that a Context can play a role in another Context.


I think the opposite is also true, Role is Context for other Roles.

Raoul Duke

unread,
Feb 28, 2019, 1:32:05 PM2/28/19
to object-co...@googlegroups.com
nietzsche said: when you gaze into the navel, the navel also gazes back into you. 

Oleh Novosad

unread,
Feb 28, 2019, 1:32:27 PM2/28/19
to object-composition


On Thursday, 28 February 2019 13:24:43 UTC-5, Oleh Novosad wrote:
the point seems to be that a Context can play a role in another Context.


I think the opposite is also true, Role is Context for other Roles.

I think this actually summarizes this conversation. This is what I meant from the very beginning:

"Contexts are actually Roles but Roles when you look at them from outside. 
Roles are Contexts but when you look at them from inside."


James Coplien

unread,
Feb 28, 2019, 1:41:09 PM2/28/19
to object-co...@googlegroups.com


On 28 Feb 2019, at 19.24, Oleh Novosad <oleh.n...@gmail.com> wrote:

I think the opposite is also true, Role is Context for other Roles.

No. Just no.

My own suggestion would be either to read the Lean Architecture book, or to download the trygve programming environment, read its user manual, and write some code. I think just making guesses and letting us say “yes” and “no” isn’t going to get you there.

Oleh Novosad

unread,
Feb 28, 2019, 1:50:10 PM2/28/19
to object-composition
 Trygve said that "the point seems to be that a Context can play a role in another Context."
If Context can be Role it means Role is Context for what was inside of that Context. So it is just a logical conclusion that "Role is Context for other Roles".

James O Coplien

unread,
Feb 28, 2019, 2:33:14 PM2/28/19
to object-co...@googlegroups.com


On 28 Feb 2019, at 19.50, Oleh Novosad <oleh.n...@gmail.com> wrote:

If Context can be Role it means Role is Context for what was inside of that Context. So it is just a logical conclusion that "Role is Context for other Roles".

This is imprecise language. We need precision here.

"If Context can be Role” No, it can’t. A Context instance may play a Role.
“Context” is ambiguous and may or may not be an instance.
“Be a Role” is much different than “play a Role.”

"it means Role is Context”

No, Role is never Context.

"for what was inside of that Context”

What do you mean by “inside of that Context”? Inside of its declaration? Contained in an instance? Declared within the lexical scope of the Context declaration?

"So it is just a logical conclusion that "Role is Context for other Roles”.

For a suitable redefinition of English I suppose you are right. But English is not working here, and I can appreciate that that might be difficult. Please use code. I appreciate your attempt with pseudo-code, but it would be much better in something that runs. Hopefully that is your goal, eventually, anyhow, so you might as well get started.

Quang

unread,
Feb 28, 2019, 2:38:15 PM2/28/19
to object-composition
I think you get too much into the language debate.

In DCI:
- Every object can play a Role in a Context
- Context is an object so it can PLAY a Role in a Context (even within itself)

Your theory does not make sense:
You said: 
a Context can play a role in another Context --> Yes
If Context can be Role it means Role is Context for what was inside of that Context --> does not make sense here

To PLAY is not TO BE

- So there is not such thing Context is Role and Role is Context.... --> this just has gone too far in the land of language mystery :)

Keep it really simple, inject a Context as an object in another Context as a Role and add Role methods into it as needed then move on.

/quang

Oleh Novosad

unread,
Feb 28, 2019, 2:47:42 PM2/28/19
to object-composition


On Thursday, 28 February 2019 14:38:15 UTC-5, Quang wrote:
I think you get too much into the language debate.

In DCI:
- Every object can play a Role in a Context
- Context is an object so it can PLAY a Role in a Context (even within itself)

Your theory does not make sense:
You said: 
a Context can play a role in another Context --> Yes
If Context can be Role it means Role is Context for what was inside of that Context --> does not make sense here

To PLAY is not TO BE

- So there is not such thing Context is Role and Role is Context.... --> this just has gone too far in the land of language mystery :)

OK, we have "Context" and "Context instance". Context instance is an object (data in memory), so yes it can play Role. I agree.

But Context (not Context instance) is just a code, and Role is just a code. 

And yes I am saying that Context is Role from outside and Role is Context from inside.

And showed it my example where Theatre Context can be easily rewritten as Theatre Role and that Role can be applied to Building object/instance and everything works.

 

Oleh Novosad

unread,
Feb 28, 2019, 2:59:20 PM2/28/19
to object-composition


Cope wrote:
Contexts can play Roles. Contexts are not Roles.

If language was not precise, I think it was not precise from both sides. Above Cope probably meant "Context instances can play Roles" instead of  "Contexts can play Roles."

Oleh Novosad

unread,
Feb 28, 2019, 3:21:27 PM2/28/19
to object-composition
 

Maybe I can rephrase my point this way:

Can I inject Context (not Context instance) into some object/instance in the same we do it with Roles? If not, why?

Rune Funch Søltoft

unread,
Feb 28, 2019, 3:24:40 PM2/28/19