The answers may depend upon your project needs. You should think about
the language you use to describe the use case.
I don't include "Context" or "Role" in my names; it's redundant.
I often find myself choosing a gerund for a context name (e.g.
BookPurchasing), but not always.
A role is what your object is. You are a waiter, a chef, a customer,
etc. Nouns fit that well.
Is there an established set of naming conventions contexts and roles within DCI? Specifically, I'm interested in advice on the following:* Should context classes be named as nouns, verbs, or other?
* What form of speech should roles be named with?
* Is it common to use suffixes on context and/or role names to identify them as such (i.e. TransferMoneyContext, SourceAccountRole, etc.)
On Thu, May 10, 2012 at 12:45 AM, Justin Ko wrote:
>
> On May 9, 2012, at 9:32 PM, Jim Gay wrote:
>
>> On Wed, May 9, 2012 at 6:14 PM, Justin Ko wrote:
>>> I prefer to know when a class is a context, and not a service class, for
>>> example. Name spacing (Contexts::TransferMoney) or suffix helps with this,
>>> and also avoids name collisions.
>>>
>>
>> I'm curious about this. Why do you need to know if you have a context
>> or a service class?
>
> When you're dealing with an object, you want to know what its responsibilities are. Our mental model for a context is different than for a service (at least to me). We have certain expectations for a context: dumb, dumber, triggers, state, use case, etc. Therefore, when viewing the context object "in action", I can "fail" these expectations in my head to produce better code or a better design. For example, if I see a context object call a method that serializes itself to JSON (with some added nodes for logic), I can throw a red flag. If this context's class is named "SerializeObject", it could be a service class, utility class, etc. and serializing itself is perfectly valid.
>
> Of course, if you forget or don't know what the class is, you can always use your editor to quickly find out, but that adds mental overhead.
I'm not sure I fully understand your argument.
Have you actually had this problem or are you anticipating it?
What we can learn from DCI is that *any* object is or can be a
context. If you create a program where an Account is a simple object,
but later realize that it's much more complex than that and its
internal structure is that of collaborating objects, would you go and
change all references from Account to Context::Account? What benefit
would that give you? The behavior is still the same, but the
composition is different. Outside that object, your program only cares
about the behavior.
>
> Imagine the challenges created if half of the women in the world suddenly had boy names...
I don't think that's an apt comparison, but I understand your point.
>
>> When, in your own code, would you have name collisions on something
>> like TransferMoney?
>
> Name collisions are easy.
>
> For example, in Rails, if you create a database migration named "CreateUsers", you'll get a top-level class named CreateUsers. Hmmm, that name sounds like a service class to me. I suffix all of my migration classes with "Migration".
>
That seems like a fine solution. You would be better served to merely
rename your migration. You *never* type the name of a migration in
your program. Its name is incidental, so you should preserve the name
you want (CreateUsers) for your own needs.
> Also, the odds of a name collision increase ten-fold for newcomers to a codebase. Avoid surprises by being a tiny bit more verbose.
That sounds like hyperbole.
And I'd err on the side of naming a service class explicitly. I
personally don't often use service classes, so they are more rare in
my programs. If I use DCI, typing Context:: all over would annoy me
especially if I chose a convention like that and refactored existing
objects and classes to go from non-context to context.
“In ALGOL 60, the rules of the language have been carefullyDCI is different from all this:
designed to ensure that the lifetimes of block instances are
nested, in the sense that those instances that are latest
activated are the first to go out of existence. It is this feature
that permits an ALGOL 60 implementation to take advantage
of a stack as a method of dynamic storage allocation and
relinquishment. But it has the disadvantage that a program
which creates a new block instance can never interact with it
as an object which exists and has attributes, since it has
disappeared by the time the calling program regains control.
Thus the calling program can observe only the results of the
actions of the procedures it calls. Consequently, the
operational aspects of a block are overemphasised; and
algorithms (for example, matrix multiplication) are the only
concepts that can be modelled.” [Dahl1972]"
---
"Two simple changes:
“In SIMULA 67, a block instance is permitted
to outlive its calling statement, and to remain
in existence for as long as the program needs
to refer to it.” [Dahl1972]
A way of referring to “it”: object references as
data."
---
Dahl was inspired by
visualizing the runtime
representation of an Algol 60
program:
Objects were already in
existence inside every
executing Algol program —
they just needed to be freed
from the “stack discipline”
Any object regardless of it's behaviour/interface can be implemented as a context. Whether or not that it is will not be visible from the outside. -Rune
Trygve Reenskaug mailto: try...@ifi.uio.no
Morgedalsvn. 5A http://folk.uio.no/trygver/
N-0378 Oslo Tel: (+47) 22 49 57 27
Norway