In a Rails application, a controller action is the Context. When no
logic aside from the use case needs to be described that seems to be
true.
When we need to run an "if" block to check for some environment or
object attribute, then we could either look at the entire action as a
Context, or look at the executed block of the "if/else" as a Context.
I've seen sample code on this list refer to instantiating some type of
Context object and executing the algorithm defined in it, but as far
as I can tell in my world, I have no need for that.
I can only see a need to create a type of Context object if the use
case could be performed outside of the controller action, for example,
from a command line interface, but even then this is hypothetical and
might still warrant it being treated separately.
When a method from a Role is performed we could be initializing a
separate Context within some method block but doing so defeats the
purpose of DCI in making readable code.
I've been thinking about the DCI approach as OOOP (Obvious Object
Oriented Programming)
--
Jim Gay
Saturn Flyer LLC
http://www.saturnflyer.com
571-403-0338
> Think of a Context object as a component which contains roles.
That's hard for me to do, because objects exist at run time and roles exist at compile time.
Thanks for the feedback, Ant.
But your argument doesn't convince me that I'm incorrect in my understanding.
A Rails controller initializes and calls a method to respond to some
request. That method block, or instance of the controller if you
prefer, serves as the Context; it has knowledge of the
request/response (the environment) and does the job of gathering the
necessary data objects and the roles required for those objects to
perform whatever tasks are necessary.
As far as I can tell, your completeSale method is just a way to hide
your algorithm somewhere else. But isn't that the opposite of what we
intend to do with DCI? And are you using this method elsewhere in your
application?
A Context should only be created explicitly as an object if it can be
reused somewhere. When a user interacts with a web application, each
controller action and response is unique. If there are reusable parts,
only then would I expect to create another object to handle it.
Even so, and as far as I can tell, the Context is a conceptual
structure so a method can and should serve as the Context where
necessary. It seems to me that the DCI paradigm encourages us to make
code reusable from the perspective of clarity of use and to avoid
burying functionality like that.
In the Rails world there's a lot of encouragement for "skinny
controllers and fat models" meaning you move all that you can down
into the model layer.
As I understand DCI, it says that these should not be in the model
layer (which is really just the class) but should be very obviously
applied to the object layer (the forgotten layer in most applications
without DCI). The place that makes the most sense to do this, and the
place that seems to be the Context, is the individual controller
action.
For what other reason (besides reuse) would I need an explicite
context object? If an instance of my controller performing an action
serves as the context, why obfuscate into another object?
>> Even so, and as far as I can tell, the Context is a conceptual
>> structure so a method can and should serve as the Context where
>> necessary. It seems to me that the DCI paradigm encourages us to make
>> code reusable from the perspective of clarity of use and to avoid
>> burying functionality like that.
>
> While DCI is about clarity, it is more about putting the algorithms in
> the right place - and that place is not in a class, rather in a "role"
> - which is a set of methods which are added to an object for just as
> long as it needs their behaviour, i.e. during the life of the context.
The "role" is not the place for the algorithm. The Role is something
an object plays. The context is the place for the algorithm and it
coordinates the objects, roles, and the interaction among objects.
>> In the Rails world there's a lot of encouragement for "skinny
>> controllers and fat models" meaning you move all that you can down
>> into the model layer.
>>
>> As I understand DCI, it says that these should not be in the model
>> layer (which is really just the class) but should be very obviously
>> applied to the object layer (the forgotten layer in most applications
>> without DCI). The place that makes the most sense to do this, and the
>> place that seems to be the Context, is the individual controller
>> action.
>
> The behaviour which is in fat controllers, i.e. algorithms, which you
> are being encouraged to move into the model, should be moved into the
> model if you do DCI. They should be moved into rolemethods - methods
> belonging to roles. The context then injects (or some other way) the
> role methods into the relevant objects so that they can do their
> stuff.
>
> If you just move all the behaviour into the model, then its plain OO.
> And the problem is, its not really clear which methods are used when -
> you just have a heap of attributes and methods and it is hard to see
> what is useful for a specific use case or collaboration.
This is exactly what I am saying here. But I'm raising the question
about whether the instance of the controller performs the task of the
Context.
I see no explicit reason that an instance of a controller could not
perform this function, nor why it doesn't make sense to do so.
I agree completely with this. In a web framework, a separate object
would make unit testing simpler too, but I see that as an artifact of
testing in the relationship to a request and response (which
complicates the setup).
>
> Compare to writing a standalone application: you can do a lot of
> things in the static main procedure, maybe you don't see the need to
> do OOP at this level, so you don't need a main instance and do a lot
> of coding in - say - Pascal style. Still it's probably good practice
> to leave the procedural level and create instances and delegate
> execution to these instances as soon as possible, just to consistently
> leverage the OO paradigm.
>
> Sure, a controller method can already be used as a grouping mechanism
> holding some variables and initiating interaction among the referenced
> objects. A context object is basically a more powerful grouping
> mechanism. How much more power depends on what church you go to. OT/J
> tries not to limit your freedom so in that language a context can be
> used for grouping all of these: role classes, role instances, role
> assignment, role state, context state, and contexts can be aggregated
> from smaller contexts and can be refined using inheritance. Nobody
> forces you to use all of these right away (some may say, some of these
> concepts are evil), but as a system grows and evolves my experience
> tells me that you'll appreciate all of these sooner or later.
>
> cheers,
> Stephan
I can see that. I've been doing a lot of thinking about this and
working with 2 projects to test out the ideas to see how they feel.
When first approaching this, however, I can see a controller action
that just initializes some type of context object and moves all the
decisions there. Looking at that, I step back and wonder, "for what
concrete reasons would I need that other object assuming that my
controller action is only run in a certain situation (the context) and
not reused with varying parameters?"
As I'm thinking through this I'm also trying to find conventions. What
will I name my context objects in a way that makes sense with the use
case?
In Rails, for example, the models and controllers are often tightly
mapped. Creating a Product goes through the ProductsController.
Perhaps needs will be different, but that makes a lot of sense when
getting started.
The value I see in having an explicit Context object (not the
controller) is that I can write my program without respect to how it
is performed.
For example if I create a CustomerBuysTacos object, I can develop a
completely functioning application and where that context gets the
data that it needs, assigns the roles, and performs the actions
*without hooking it into an implementation*.
I could create this program and later decide that instead of a web
application, it is a desktop application, or mobile phone application.
By starting with the context object separately, I can worry about web
API endpoints later and layer on my integration tests to ensure that
the implementation matches the use cases.
For what other reason (besides reuse) would I need an explicite
context object? If an instance of my controller performing an action
serves as the context, why obfuscate into another object?
--
You received this message because you are subscribed to the Google Groups "object-composition" group.
To post to this group, send email to object-co...@googlegroups.com.
To unsubscribe from this group, send email to object-composit...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/object-composition?hl=en.
Well, to be fair: DCI is a complement to MVC, is it not? I'm not
convoluting the two, I'm trying to discern how one complements the
other.
> Several controllers usually take part in one use case.
I'm very curious about this comment. Is this necessarily true? Why?
If we're talking about HTTP requests, then we're working with a
stateless environment, but I imagine that by involving multiple
controllers I'd need to be keeping track of state. If that's true,
then either you're implying that it should track state, or I'm
misunderstanding something.
I recognize that my comments here map a 1 to 1 relationship with HTTP
requests and controller functions. Perhaps you're thinking
otherwise...?
> The context is not part of the controller action or even the controller,
> rather more controllers take part of the execution of one interaction
> The context therefor comes before the controller.
> So another way of phrasing your own question would be If you already have a
> context what's the action doing?
> -Rune
>
--
>>
>> Several controllers usually take part in one use case.
>
> I'm very curious about this comment. Is this necessarily true? Why?
I am curious, too, and would be very surprised to find it so.
2011/9/28 rune funch <funchs...@gmail.com>
2011/9/28 Jim Gay <j...@saturnflyer.com>For what other reason (besides reuse) would I need an explicite
context object? If an instance of my controller performing an action
serves as the context, why obfuscate into another object?I believe that trying to learn DCI by looking at MVC is like trying to build a plane by looking at a car. They are similar in some respects that you might actually be convinced you could just mount wings on the car at it fly. (not accepting that Harry Potter could just wish it to do so)There's an overlap between MVC and DCI but firstly MVC does not segregate what the system is and what it does. It doesn't help you keep the algorithm in one place either. Several controllers usually take part in one use case.The context is not part of the controller action or even the controller, rather more controllers take part of the execution of one interactionThe context therefor comes before the controller.So another way of phrasing your own question would be If you already have a context what's the action doing?-RuneI like to reason the connection between MVC and DCI so that in DCI you simply take that M away, and replace it with DCI. So DCI + MVC becomes DCI + VC.
A use case doesn't map 1:1 to http request. Thick of booking one
return flight say from Copenhagen to Berlin how many round trip do you
have to the server before you're done? It's one use case none the less
>> The context is not part of the controller action or even the controller,
>> rather more controllers take part of the execution of one interaction
>> The context therefor comes before the controller.
>> So another way of phrasing your own question would be If you already have a
>> context what's the action doing?
>> -Rune
>>
>
>
>
> --
> Jim Gay
> Saturn Flyer LLC
> http://www.saturnflyer.com
> 571-403-0338
>
My assumption is the usual MVC framework not MVC.
I haven't seen anything that suggests this. In fact, in the article
"The DCI Architecture: A New Vision of Object-Oriented Programming"
(http://www.artima.com/articles/dci_vision.html) Figure 5 clearly
shows that DCI is not a replacement of the model. It is a coordination
of concerns in the use case where DCI takes into account the needs of
the objects and how they act and what is displayed.
This assumes that you'll implement it in a way that requires multiple
round-trips. Perhaps there's only 1 flight to select, or perhaps all
the information you need can be presented in a single resource. Your
example implies a use case, but we don't actually have any of the
constraints about it here.
Regardless of that, a single instance of a controller performing an
action still could act as the Context.
> On Wed, Sep 28, 2011 at 12:11 PM, rune funch <funchs...@gmail.com> wrote:
>> Thick of booking one
>> return flight say from Copenhagen to Berlin how many round trip do you
>> have to the server before you're done? It's one use case none the less
>
> This assumes that you'll implement it in a way that requires multiple
> round-trips. Perhaps there's only 1 flight to select, or perhaps all
> the information you need can be presented in a single resource. Your
> example implies a use case, but we don't actually have any of the
> constraints about it here.
Interesting. How will you find possible flights before you know when I
want to fly? How will you know what the the price is before I've
picked the flights? Do I want insurance? Check in bagages?
> Regardless of that, a single instance of a controller performing an
> action still could act as the Context.
Sure the interaction on a context could serve the purpose of an action
>
> --
> Jim Gay
> Saturn Flyer LLC
> http://www.saturnflyer.com
> 571-403-0338
>
These questions assume that the answers are relevant.
We could have a service that flies daily at the same time from
Copenhagen to Berlin with everything included.
Here's a simple use case:
Customer selects the flight date and purchases the seat.
In the case of a more complicated example, what would be your use
case, and how would the Context object fit in?
>> Regardless of that, a single instance of a controller performing an
>> action still could act as the Context.
> Sure the interaction on a context could serve the purpose of an action
That reads like you reluctantly accept it. If that's so, why be reluctant?
Why should I *not* think of the controller action in this way?
Den 28/09/2011 kl. 18.36 skrev Jim Gay <j...@saturnflyer.com>:
> On Wed, Sep 28, 2011 at 12:26 PM, rune funch <funchs...@gmail.com> wrote:
>> Den 28/09/2011 kl. 18.20 skrev Jim Gay <j...@saturnflyer.com>:
>>
>>> On Wed, Sep 28, 2011 at 12:11 PM, rune funch <funchs...@gmail.com> wrote:
>>>> Thick of booking one
>>>> return flight say from Copenhagen to Berlin how many round trip do you
>>>> have to the server before you're done? It's one use case none the less
>>>
>>> This assumes that you'll implement it in a way that requires multiple
>>> round-trips. Perhaps there's only 1 flight to select, or perhaps all
>>> the information you need can be presented in a single resource. Your
>>> example implies a use case, but we don't actually have any of the
>>> constraints about it here.
>> Interesting. How will you find possible flights before you know when I
>> want to fly? How will you know what the the price is before I've
>> picked the flights? Do I want insurance? Check in bagages?
>
> These questions assume that the answers are relevant.
> We could have a service that flies daily at the same time from
> Copenhagen to Berlin with everything included.
> Here's a simple use case:
> Customer selects the flight date and purchases the seat.
But it's not any giving use case but your average use case for a low
fare flight. Easy jet ryanair or similar.
> In the case of a more complicated example, what would be your use
> case, and how would the Context object fit in?
>
>>> Regardless of that, a single instance of a controller performing an
>>> action still could act as the Context.
>> Sure the interaction on a context could serve the purpose of an action
>
> That reads like you reluctantly accept it. If that's so, why be reluctant?
> Why should I *not* think of the controller action in this way?
I'm not reluctant at all I just think you have it upside down. The
interaction of the context replaces the action. You don't have roles
in a controller and hence it's no context.
>
> --
> Jim Gay
> Saturn Flyer LLC
> http://www.saturnflyer.com
> 571-403-0338
>
> Regardless of that, a single instance of a controller performing an
> action still could act as the Context.
That makes for a pretty fat controller, which is bad design.
Never said you could create a simple UC that only requires one round
trip. We don't have any in the project I'm on but that doesn't mean
that I could come up with one
-Rune
>
> In the case of a more complicated example, what would be your use
> case, and how would the Context object fit in?
>
>>> Regardless of that, a single instance of a controller performing an
>>> action still could act as the Context.
>> Sure the interaction on a context could serve the purpose of an action
>
> That reads like you reluctantly accept it. If that's so, why be reluctant?
> Why should I *not* think of the controller action in this way?
>
> --
> Jim Gay
> Saturn Flyer LLC
> http://www.saturnflyer.com
> 571-403-0338
>
> Why should I *not* think of the controller action in this way?
One reason is separation of architectural concerns. MVC separates the presentation from the code that feeds it; DCI separates data from use case. There is no use case line in MVC: indeed, MVC is built more around reactive events than anything with long-term temporal structure. Aligning the structures of DCI with MVC can artificially constrain evolution by arbitrarily aligning two independent shear lines.
Second, this makes for a fat Controller — which is another way of saying that it is poor separation of concerns.
People keep bringing up web interfaces here. Many web interfaces — especially airline reservation systems — are much less modal than the examples here suggest, so I can argue that they function as atomic event architectures. And you give the user more flexibility if you design them that way. I can jump around from screen to screen at will. I might start with a selection of class of seats — e.g., business class — before selecting an origin and destination. Or I might select a flight that infers an origin and destination, and then select a flight class. After doing either of these I might back up and edit my selections and do another search. Most real-world web interfaces don't lend themselves well to use cases — only in kiddie text books, and college course examples... A few web interfaces that were built to simulate old forms-based interfaces from the IBM green-screen world do have use-case nature, and those are great for DCI.
> Never said you could create a simple UC that only requires one round
> trip. We don't have any in the project I'm on but that doesn't mean
> that I could come up with one
However, few use case experts (Cockburn, Wirfs-Brock) would think of that case as being their primary target for a use-case approach. An atomic event architecture is more suitable to single-round-trip interactions. A use case is a sequence of interactions (by definition): not an interaction.
That's helpful. I have more research to do.
This makes me think of the need for nested or related contexts where a
front end DCI layer in JavaScript (for example) would in some way
execute another context on the server side.
If this is true, then how does DCI fit into this multi-interaction web
implementation?
In my initial thinking, I've been throwing away the context with the
request (it's done when the request is done), but this seems to
suggest otherwise.
Earlier you commented that on this (the last line being Cope):
>>> Several controllers usually take part in one use case.
>>
>> I'm very curious about this comment. Is this necessarily true? Why?
>I am curious, too, and would be very surprised to find it so.
But doesn't your above comment about web interfaces imply that several
controllers would or could take part in one use case?
> If this is true, then how does DCI fit into this multi-interaction web
> implementation?
Whereever there are use cases that one can describe in terms of role interactions.
> In my initial thinking, I've been throwing away the context with the
> request (it's done when the request is done), but this seems to
> suggest otherwise.
The lifetime of a Context is the lifetime of a use case.
> Earlier you commented that on this (the last line being Cope):
>
>>>> Several controllers usually take part in one use case.
>>>
>>> I'm very curious about this comment. Is this necessarily true? Why?
>> I am curious, too, and would be very surprised to find it so.
>
> But doesn't your above comment about web interfaces imply that several
> controllers would or could take part in one use case?
No. In my view the Controller is most tightly bound to the input devices and the domain objects. It is just MVC 101 that views come and go under the oversight of the Controller, and that the objects whose state is displayed by the views themselves outlive the views. Those objects map vary closely to DCI objects.
The lifetime of a Controller therefore tends to be the life of a session, which may bracket several use cases and other user inputs. Not all user inputs are well-characterized as use cases.
It is likely that the Controller instantiates Context objects. There is a unique Context class for each use case. The identify of that class in turn derives from the Controller's "parsing" of the end-user input.
There is a many-to-many-to-many... association between these objects. The only alignment between MVC and DCI that I see is that what DCI calls objects maps onto the objects whose states are observed by MVC views. Other than that, I don't see much more association that between any other two frameworks. It is probably common that the Controller instantiates Contexts, but it is equally likely that the Controller directly invokes methods on the more general (domain) objects. The latter is the atomic event architecture; the former is the DCI architecture.
What if we had Context that acted also as a form-input-checking-controller called "Controller" in typical web-MVC-frameworks?
On Sep 28, 2011, at 6:59 , Jim Gay wrote:
> If this is true, then how does DCI fit into this multi-interaction web
> implementation?
Whereever there are use cases that one can describe in terms of role interactions.
DCI is too good hammer to be used only to Use Case nails, methinks.
My understanding is that the Context should describe the Use Case in code.
I don't think it's DCI but is focusing on extending the behavior of
objects is the hammer that you like.
The way I envision the Context, in light of this, is that web requests
should be able to, in some way, resume the operation of a context.
My Context describes the code necessary for the use case, but in a web
framework each user action (and web request) would be some part of the
algorithm in the overarching context. Is that on the right track?
Or does this mean, essentially, that the web MVC that I'm used to is
inherently not DCI compatible?
> My understanding is that the Context should describe the Use Case in code. I don't think it's DCI but is focusing on extending the behavior of objects is the hammer that you like.
I don't understand your response. Can you expand or add a conceptual example?
Habit, for example. That's UC, but without business value.
And also non-interactive, non-human related actions that clearly involve communication between objects with different Roles fits Context perfectly, I think.
I had also an example of a broader Context in my mind, but I'm just now too tired to express myself meaningfully.
I guess Trygve could tell us some examples of Context that doesn't have anything to do with Use Cases.
> The way I envision the Context, in light of this, is that web requests should be able to, in some way, resume the operation of a context.
They can if they're stateful. That something is a use case doesn't say where the state is stored. It could be in a cookie, inferred from a cookie, or in the client or in the server. Use cases have nothing to do with the implementation technology. They are business behavior.
> My Context describes the code necessary for the use case, but in a web framework each user action (and web request) would be some part of the algorithm in the overarching context. Is that on the right track?
If it truly is an algorithm that can be defined in terms of a succession of states, then it can be DCI. I envision all of that happening under a single Controller unless I'm switching heads (keyboard and screen, or other HCI) in the middle of the use case.
> Or does this mean, essentially, that the web MVC that I'm used to is inherently not DCI compatible?
Not enough information to know.
> I would also like to turn the original question up side down: why
> shouldn't a controller action and context be two objects? What is so
> painful about having two objects?
There is no need to reify actions, certainly not at the analysis / use case level. If you need to turn an action into a message at the low level (for the sake of a client / server architecture) that, to me, seems below the DCI abstraction layer. It's just a matter of programming using patterns like HOPP.
--
You received this message because you are subscribed to the Google Groups "object-composition" group.
To post to this group, send email to object-co...@googlegroups.com.
To unsubscribe from this group, send email to object-composit...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/object-composition?hl=en.
Trygve Reenskaug mailto: try...@ifi.uio.no
Morgedalsvn. 5A http://folk.uio.no/trygver/
N-0378 Oslo Tel: (+47) 22 49 57 27
Norway
I guess Trygve could tell us some examples of Context that doesn't have anything to do with Use Cases.That's a challenge. He'd probably say that it's a matter of definition.
But is this it is an example of Context that doesn't have anything to do with Use Cases? It is a question of definition.
> I would also like to turn the original question up side down: why
> shouldn't a controller action and context be two objects? What is so
> painful about having two objects?
Bingo. Avoid fat controllers. You don't want 90% of your system's logic in one class.