-Rune
> --
> 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.
>
Mvh
Rune
> suggesting to me that they too are having problems
or not motivated enough to invest time in it:)
>> @James: I am still waiting for you to provide hints on how to write
>> the use case, or even write it if you feel so inclined ;-)
After you posted your initial code, there were some follow-on comments that I thought might move you to change your code. I was waiting for that to settle down before jumping in to do a use case.
It's by far not as likely in this scenario, because
a) role methods can't mess up the object's internal state, and
b) role player methods can, but they will probably (definitely?) complete before control goes back to a role method.
But still, conflicts are not beyond imagination.
class Role1
{
A()
{
oldValue = this.RolePlayerProperty1;
this.RolePlayerProperty1 = newValue;
Role2.B(); // written assuming that Role2 is another object
this.RolePlayerProperty1 = oldValue;
}
}
class Role2
{
B ()
{
this.RolePlayerProperty1 = someOtherValue;
}
}
Yes, I know, it's far-fetched. Another trap could be a role player method like BeginXxx() that exits in an inconsistent state, to be paired by an EndXxxx() method.
Stefan
On Di, Okt 04, 2011 at 18:31:54, rune funch wrote:
> Subject: Re: One object, many roles... identifier naming
Is ToPrint not a system operation (context) which uses two data objects of what needs printing and the printerspool?
Daatobjects
Printerspool
Document
Context
Print
?
:-)
Gesendet von meinem HTC
----- Ursprüngliche Nachricht -----
Von: James O. Coplien <jcop...@gmail.com>
Gesendet: Mittwoch, 5. Oktober 2011 15:25
An: object-co...@googlegroups.com <object-co...@googlegroups.com>
Betreff: Re: One object, many roles... identifier naming
:-)
--
Hopefully you are using methods to set things like RolePlayerProperty1. Anyone who directly accesses member data of a subclass or superclass is a doofus.
Mvh
Rune
Like I said, it's much less likely for roles than for objects, but it seems to be there.
> -----Original Message-----
> From: object-co...@googlegroups.com [mailto:object-
> compo...@googlegroups.com] On Behalf Of rune funch
> Sent: Thursday, October 06, 2011 3:22 PM
> To: object-co...@googlegroups.com
> Subject: Re: AW: Re: One object, many roles... identifier naming
>
> A property in C# is by definition a field with a getter and/or setter
> method. Since Stefan is from C# I guess we can assume property to have
> the C# semantics
>
> Mvh
> Rune
>
> Den 06/10/2011 kl. 15.19 skrev "James O. Coplien" <jcop...@gmail.com>:
>
> > The object should be responsible for its own re-entrancy - not the
> role that the object is playing. If it is, then there is no problem.
> >
> > Hopefully you are using methods to set things like
> RolePlayerProperty1. Anyone who directly accesses member data of a
> subclass or superclass is a doofus.
> >
> >
> > On Oct 6, 2011, at 10:00 , Wenig, Stefan wrote:
> >
> >> Sorry, ambiguous pseudocode. oldValue is supposed to be a local
> variable in a role method.
> >>
> >> Gesendet von meinem HTC
> >>
> >> ----- Ursprüngliche Nachricht -----
> >> Von: James O. Coplien <jcop...@gmail.com>
> >> Gesendet: Mittwoch, 5. Oktober 2011 15:25
> >> An: object-co...@googlegroups.com <object-
> >> Betreff: Re: One object, many roles... identifier naming
> >>
> >>
> >> Roles don't have state. oldValue is state. This is not a role. QED.
> >>
> >> :-)
> >>
> >>
> >> On Oct 5, 2011, at 1:14 , Wenig, Stefan wrote:
> >>
> >>> class Role1
> >>> {
> >>> A()
> >>> {
> >>> oldValue = this.RolePlayerProperty1;
> >>> this.RolePlayerProperty1 = newValue;
> >>>
> >>> Role2.B(); // written assuming that Role2 is another object
> >>> this.RolePlayerProperty1 = oldValue;
> >>> }
> >>> }
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups "object-composition" group.
> >> To post to this group, send email to object-
> >> To unsubscribe from this group, send email to object-
> composition...@googlegroups.com.
> >> For more options, visit this group at
> http://groups.google.com/group/object-composition?hl=en.
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups "object-composition" group.
> >> To post to this group, send email to object-
> >> To unsubscribe from this group, send email to object-
> composition...@googlegroups.com.
> >> For more options, visit this group at
> http://groups.google.com/group/object-composition?hl=en.
> >>
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "object-composition" group.
> > To post to this group, send email to object-
> > To unsubscribe from this group, send email to object-
> composition...@googlegroups.com.
> > For more options, visit this group at
> http://groups.google.com/group/object-composition?hl=en.
> >
>
> --
> You received this message because you are subscribed to the Google
> Groups "object-composition" group.
> To post to this group, send email to object-
> To unsubscribe from this group, send email to object-
> composition...@googlegroups.com.
I think the problem you're touching here as two parts, and they're both about the SRP.
- on the data side: Why would I create such a large object? I don't see a reason. I think you're separating your system into several classes in your head, just to create a single class in your implementation. Maybe that's really SOA thinking, it makes more sense as a service façade than within an OO system. DCI deals with individual objects, not with entire systems. The context can act as a façade, but that shouldn't show in the context's inner workings.
- on the role side: I can bind a single object to several roles, but usually that's just an indicator that that object has a problem. If I do, it will usually work fine, but I think there's a risk if the various roles affect each other through some object state that's shared between this roles (like that reentrancy scenario)
Stefan
> -----Original Message-----
> From: object-co...@googlegroups.com [mailto:object-
> I thought it was worthwhile challenging Rune's assumption that this is a harmless scenario
Since this commentator is not connected (in writing) to anything I
don't know what you're referring to unfortunately. I guess it's my
comment on an object playing multiple roles at the same time. If
that's the case then I never said I believed it to be harmless only
that I could see scenarios where it makes a lot of sense. May I
suggest that we all keep the text we're commenting on together with
the comment.
In general I don't think the interaction should be concerned with what
object plays what role and if the binding has a sensible scenario
where it picks the same object to play multiple roles then it's by
definition makes sense. Eg. If I have a VCS and I wish to compare line
for line who edited that line in the history of the file. I'm only
interested in two devs work on the LHS of the screen I have all lines
devA have ever edited all other lines are blank and on the RHS I have
the same for devB. If the same object couldn't play two roles at the
same time I'm not matching the mental model of the two views being of
the same file. The use case how ever let me see any two views. Two
different files same dev, two different files and devs and same file
same dev are all valid variations of the use case.
-Rune
> In general I don't think the interaction should be concerned with what object plays what role
This has limited truth as a statement in isolation; the second half of the sentence makes it true.
Just a couple of observations.
First, more precisely: "the interaction should not be concerned with the class of the object that plays a given role." That isn't object thinking.
Second, no object should, in general, be concerned about how many roles it is playing. That really complicates the relationship between what-the-system-is and what-the-system-does. Again, this would be a good research topic, to show what kinds of separations of concerns should be enforced in a class's role extension interface.
Third, no role, in general, should be concerned whether its object is playing another role. There can be corner cases where this is true but I consider it to be bad design: creating entities unnecessarily. And, in any case, the Context needs to deal with this issue more broadly.
Fourth, whether it makes sense for an object to play multiple roles within a given Context is the job of the Context, and in particular of the rebind method.
> and if the binding has a sensible scenario where it picks the same object to play multiple roles then it's by definition makes sense.
Exactly, exactly.
This is strongly analogous to a situation in procedural design. Good procedures are designed to work independent of the context from which they are called. The call graph of a procedural program is not a tree. It is a directed graph, potentially cyclic. The same is true in some degree with role / object bindings. A role is a name for an object, and there's nothing wrong with an object having many names — just as in "real life."
ok, so listing 2 is ok.
On Oct 7, 11:07 am, "James O. Coplien" <jcopl...@gmail.com> wrote:
> A role is a name for an object, and there's nothing wrong with an object having many names — just as in "real life."
Trygve Reenskaug mailto: try...@ifi.uio.no
Morgedalsvn. 5A http://folk.uio.no/trygver/
N-0378 Oslo Tel: (+47) 22 49 57 27
Norway
Hello ant,
Id like to give it a stab at helping you. Though be warned i maybe wrong.
You managed to write down all your objects. Lets try and get them on a stage. Can you think of these objects as people? What are they doing?
Hopefully your see receipt can not be a person. It can be what a person says, or on a persons t-shirt. This is because it is a representation of something. Hopefully the bill object. :)
You can imagine the printer as someone writing down on paper what is being sent to it (or said to it).
Has the customer asked you to "program" a printer? I don't think so from ur posts, so all you need to know is that it receives the receipt.
Mike brown
> --
> 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.
Mvh
Rune
On Oct 8, 2011 4:49 PM, "rune funch" <funchs...@gmail.com> wrote:
>
> I'm confused about the system. Is this a system that runs in a
> physical till or is it an online book store?
>
> Mvh
> Rune
>
Why does that matter? Restful web ~= mvc+dci
Mike brown
> Den 07/10/2011 kl. 18.37 skrev Ant Kutschera <ant.ku...@gmail.com>:
>
> > I notice you are good at pointing out you don't like the code. Anyone
> > can do that. But only the best can then go on to show how it should
> > be done ;-)
>
> --
> 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.
Thanks :-)
The physical printer is called by a shared library (DLL, or SO) and
> Has the customer asked you to "program" a printer? I don't think so from ur
> posts, so all you need to know is that it receives the receipt.
has a low level API. An abstraction layer above that, the printer
supplier has a library which lets you send "print jobs" to the
printer.
A print job is basically a list or strings and each string is printed
on a line.
These are my current problems:
1) all roles are played by the till, so that I can pass the "is a"
test, albeit modified to be the "with" test. Eg. does this phrase
make sense: "printer = till with printer" - yes, so the role printer
is applicable to the till.
2) there is no interaction, per se. However, when I call a role
method, like "printReceipt()" I pass the basket to that method,
because it needs to print each product on the receipt. Is that
"interaction"? I guess so.
3) Many of my roles never need to call "self" to access data from the
role player (till). That seems really weird. And makes me wonder if
a better role player for "Printer" and "Sales Log" would be the
basket, because it has all the information required to create a
receipt or sales records, namely the list of products.
But a printer
"is NOT a" basket. Nor does it make sense in my mental model that
printer is a specialisation of the basket. Nor does "basket with
printer" really make sense, because a basket cannot be hooked up to a
printer.
--
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.
> The till being a plain domain object with little or no behaviour
To me the till is a system (hence my previous question whether it was
online or IRL) and I would model it as such (a context on it's own
right) and let the till context play the till role in the interaction
with the scanner and the card reader. When the steps are subdivided
some of the sub steps are going to form an interaction within the
bounds of the till system and those sub-steps would be where to find
the roles for the till context. At some point it makes no sense to
divide the steps into smaller steps at which point I would start
looking for plain data.
My 5 cents
Rune
On Di, Okt 04, 2011 at 18:31:54, rune funch wrote:
> Subject: Re: One object, many roles... identifier naming
>
> I don't see anything wrong in having the same object playing multiple
> roles at the same time. Always having the same object playing multiple
> roles does feel like a design flaw to me
>
> -Rune
I included it in my original reply, then got lost somewhere in the thread.
I never said it doesn't make sense btw, just that it might cause unexpected reentrancy problems. (And I still think that individual data objects should stick to the SRP, which the till object doesn't seem to, but that does not invalidate your statement.)
Stefan
> -----Original Message-----
> From: object-co...@googlegroups.com [mailto:object-
> compo...@googlegroups.com] On Behalf Of rune funch
> Sent: Friday, October 07, 2011 10:49 AM
> To: object-co...@googlegroups.com
> Subject: Re: One object, many roles... identifier naming
>
I notice two things. First, the till is an actor.
Second, you make no mention of accounting records, audit logs, etc.
Would those simply appear in the requirements specification?
I have to say, I am still struggling to identify roles here. Can you
help?
At step 3, the till has data about which items were scanned, their
price, etc. Steps 3-5 are done within a transaction.
The till being a plain domain object with little or no behaviour,
doesn't know how to write accounting records (done at some stage in
the transaction), or print receipts (step 5).
So that is the behaviour I need to inject with a role, right? Or how
would you do it? If that is role behaviour, what would the role name
be??
>> NO. (the till) is a role. It can be played by any one of several till objects by any number of manufacturers. I see its (domain class) behaviors as:
>>
>> - scanning price
>> - opening money drawer
>> - sensing money drawer closed
>> - displaying item cost
>> - displaying total due
>> - print receipts
>> - sums prices
>
> OK, so there is a till in the domain model. I feel those behaviours
> are quite clever ones and they are not behaviours I would typically
> put in a SOA domain object model. I thought DCI too wanted dumb
> objects?
What constitutes "smart" and "dumb" depends on the business Context. If they show up in a use case as something I expect a role to do (which they all do), then they are part of the role interface. It is certainly true that the underlying object must be able to implement them, so the object must be of a domain class that supports that functionality. "Dumb" to me roughly equates to "not part of the use case."
Further, there is a subtle role of OOD here, in that the role happens to be named Till, and you want to name the domain class Till. Design is much about the art of naming. I would call the name Till and would call the domain class NCR 3872 or IBM 4002 or whatever. Follow the vocabulary of your business.
You see, there are many design tradeoffs to be made here. They depend on your mental model. You liked the top level use case: that suggests to me that it maps to your mental model. Therefor, your mental model has a notion of the Till role that exhibits these functions. If you in fact envision something more generic, it perhaps should not go in the top level use case. Items from the more detailed use case steps may indeed be part of the data class. At some point the team needs to decide where it is going from analysis to design; at that point, the methods get "demoted" to domain class methods.
I use this argument for illustration but it's not how I usually do it. I usually start by asking myself: What are the domain classes and what generic functionality do they support (i.e., what is the abstract base class)? I use that together to help contextualize the use case behaviors. I try not to let the use case behaviors get into the domain class territory. It's a delicate balance, and the insight of all stakeholders is important to both of these.