Insights on context and role constructs

43 views
Skip to first unread message

héctor

unread,
Mar 3, 2019, 11:51:08 PM3/3/19
to object-composition
Hello everyone,

First of all, I appreciate that the forum is active, it is a huge source of knowledge for any programmer.

I’ve read the last post and I wanted to leave my perspective on some topics treated there. In general, I see that the discussion speaks of an incommensurable problem between paradigms. I think this is good as a symptom of DCI being a real paradigm, also supported in some way by the level of misunderstanding reached.

oleh > What if DANCER Role code in Theatre is not different from DANCER Role code in Bar? Literary the same code to move body parts. Why cannot I share that code between Contexts?

IMO, the confusion seems to be of context with place. A context is a phenomena that emerges from actions, is performative, is not ontological (or pre-defined), to which classes are for. The case is that considering a context ‘Theatre’ as such, carries an ontological weight. Instead, ‘Perform Dance’ can be the context (aligned with Rune, who argued that the context isn’t the Theater for the dance per se) that can occur within a ‘Theatre’ or a ‘Bar’, anywhere:

class Person {
   
public void move(String s) {
       
System.out.print(s).println("the person's movements.")
   
}
}
class Theatre {
   
public void showStage() {
       
System.out.println("the stage in the Theatre.")
   
}
}
class Bar {
   
public void showStage() {
       
System.out.println("an empty space between tables and chairs in a bar.")
   
}
}

context
PerformDance {
    role
Dancer {
       
public void dance() {
           
Place.opens_the_curtains()
            move
("The dance happens with ")
       
}
       
public void appears() {
           
System.out.print("Dancer approaches ")
       
}
   
} requires {
       
void move(String s);
   
}
    role
Place {
       
public void opens_the_curtains() {
           
Dancer.appears
            showStage
();
       
}
   
} requires {
       
void showStage();
   
}
   
public void start(Person obj, Place pl) {
       
Dancer = obj; Place = pl;
       
Dancer.dance
   
}
}
{
   
{
       
Person p = new Person();
       
Bar place = new Bar();
       
new PerformDance().start(p, place)
   
}
   
{
       
Person p = new Person();
       
Theatre place = new Theatre();
       
new PerformDance().start(p, place)
   
}
}




Given a Dancer that involves the surrounding as part of the dance, then, the surrounding can have a more participative role because the dancer interacts assiduously with the surrounding. The problem is that the place is assumed to be the context and this is not always correct. Perhaps an architect sees a theater as a context, since the architect understands the internal interactions of the building that make up the theater.

A context is not an empty container where you put things, on the contrary, it is an indivisible unit. There is no need of code duplication if we know what we understand for this unit. After analyzing the context, if we understand a dance only within a theater, then the code for a dance in a bar is another dance. In this case, the code will be different. Maybe, what is counterintuitive here is not assuming the context as the surrounding place.

Within another spectrum of possibilities, something similar happens with the role being confused with a profession or job assignations. In Jim’s example of the waiter, if we had defined all possible job responsibilities of the waiter in one role (within one context of course), the context would have become too wide and complex. Actually, it would had mixed contexts (as classes do when are written in classical OO paradigm). Then, it is clear that taking an order happens in one context, and serving food in another context.

I just observed that a context can be confused with a place or location where the action occurs, and a role can be confused with a list of responsibilities of an individual in different contexts. All this might have already been thought, but it did not appear in the post in this form. Perhaps due to the hard to parse sentences coming from other paradigm.


Reply all
Reply to author
Forward
0 new messages