Re: basic q about sequence diagrams

From: H. S. Lahman (h.lahman_at_verizon.net)
Date: 03/16/04


Date: Tue, 16 Mar 2004 21:57:59 GMT

Responding to Gawnsoft...

>>If two objects are represented in a sequence diagram with one message
>>joining them, and the message is a method call, which object is supposed to
>>have the method as one of its members?
>>
>>example if I have a car object and I want to call a method
>>car.getPassengers() to return a collection of passengers
>>
>>do I model it this way:
>>
>>[car] ------getPassengers----->[passengers]
>>or
>>[system] ------getPassengers----->[car]
>>
>>..brackets are boxes there...forgive the simplification

Let's step back to the Class Diagram. I assume we have something like:

          1 1 1 *
[Client] --------------- [Car] ------------------- [Passenger]
                R1 R2

and the Client needs to collaborate with the Car's Passengers. That is,
Client sends a message directly to each Passenger. That message is what
should appear in the Sequence Diagram and it will depend upon what the
collaboration is. For example, substitute Cop for Client:

[Cop] [Car] [Passenger]
   | | |
   | pullsOver | |
   |---------------------->| |
   | | |
   | | arrests |
   |------------------------------------------------->|
   | | |

The getPassengers method is incidental to the problem solution at the
OOA/D level. It simply implements relationship navigation, R1 -> R2, at
the OOP level. Navigating that relationship path is independent of the
class' semantics along the way.

[A translation code generator would provide quite generic, aspect-like
code for this with attributes like "Object* R1" in [Client] and
"Collection* R2" in [Car] that only a code generator could love.
Fortunately translationists rebuild the code rather than maintaining it.
  B-) For manually generated code one needs the conveniences of
meaningful names (getPassengers) and type checking during OOP.]

>
>
> The question's really about what process you are then going to draw in
> the diagram.
>
> In this example there is a Car object, associated with a number of
> Passenger objects, yes?

Yes.

>
> A Car object keeps track of how many Passenger objects it is
> associated with.

That seems like a reasonable responsibility of [Car]. However, it is
likely to be delegated to a collection class that actually implements
the 1:* association on the [Car] side. For example,

class Car
{
private:
     PtrList passengers;

public:
     getPassengerCount() {return passengers.getCount();}
}

where [PtrList] is the actual implementation of the relationship at the
OOP level and it keeps track of the number of members it has. Again,
that delegation is a convenience issue when implementing the
relationship; as far as the Client is concerned the Car still owns the
responsibility.

>
> A user wants to know how many, so enquires from the system, by sending
> a 'how many passengers do you have?' message to the car.
>
> so the answer is:
> [system] ------getPassengers----->[car]

Taken literally, that would not be a good practice. If all the client
cares about is the number of passengers, it doesn't need the passengers
themselves to determine that. It should ask for only what it does need,
which is a count. Which is why giving [Car] a public responsibility for
knowing how many passengers it has is reasonable.

*************
There is nothing wrong with me that could
not be cured by a capful of Drano.

H. S. Lahman
hsl@pathfindermda.com
Pathfinder Solutions -- Put MDA to Work
http://www.pathfindermda.com
(888)-OOA-PATH



Relevant Pages

  • Re: I bet hes Polish
    ... It became compulsory in Britain in September last year for passengers & a number of years ago for drivers & crew sitting in the crew seats. ... It is, however, virtually unenforceable, as it is the driver's responsibility to warn the passengers of the requirement, but he isn't responsible for enforcement of wearing of belts by passengers over 14, & by the time a police officer has boarded to check compliance, the vehicle is stationary, so there is no requirement to wear the belt. ... For passengers under 14, the responsible adult in charge of the child is responsible for failure to wear the belt, as in a car. ...
    (uk.transport.buses)
  • Re: basic q about sequence diagrams
    ... >>cares about is the number of passengers, ... > the context of car, I would think its ok. ... Car -- for that particular responsibility. ... Since a Sequence Diagram is an OOA/D model, ...
    (comp.object)
  • Re: North wales deaths
    ... I'm skeptical that a car could hold the ... mooted here several times - that the driver is always responsible. ... to a dscussion on appropriate speeds for the conditions, ... > responsibility for what occurs when I drive a car? ...
    (uk.rec.cycling)
  • Re: implementing roles in OOP......
    ... > must be clearly related at the level of abstraction. ... Role, responsility, type (interface), aspect and class. ... So with the Car thing - I would have a generic componentlist interface ... > When Client collaborates with Context it invokes Context.Operation. ...
    (comp.object)
  • Re: meritocracy?
    ... lights, people will soon stop running red lights. ... where "owner onus" (the responsibility of the registered car ... innocent kids in prison for over ten years. ...
    (talk.origins)