Re: How does one model behavior?

From: Leslie Sanford <>
Date: Wed, 9 Apr 2008 10:30:31 -0500
Message-ID: <47fce12c$0$11322$>

"David Cressey" wrote:
> "Leslie Sanford" wrote:


>> when designing a class I decide what it needs to do,
>> and this goes hand in hand with what it needs to know in order to do it.
>> To me it's like working with algorithms (or behavior) and data structures
>> (or data). I can't say if one comes before the other.
>> Could be my head is stuck at the code level which is where I mainly live
>> and I don't understand what it is you're asking. In which case, I welcome
>> enlightenment/clarification.
> Sorry. I don't know enough OO to provide enlightenment. I understand
> data pretty well.
> Perhaps you could tell me how you express "what a class has to do". This
> might be close to what I'm asking for when I say "how to you model
> behavior".

Well, I do it in code. Specifically at the class declaration. If a method represents the means by which an object is sent a message, then I think it's safe to say that the method name is also the name of the message. This name should reflect what behavior occurs in response to the object receiving the message. Using an example I posted in another thread:

// For fans of John Carpenter's first movie. :-) class DarkStar

    void CancelBombDetonation();

Here DarkStar can receive a message to cancel bomb detonation. So what the "class has to do" in response to this message is reflected in the message name, i.e. cancel bomb detonation. Of course, there may be a reason why the operation can't be carried out successfully, in which case an exception should probably be thrown, but I'm going to ignore that for this discussion.

If we want to go further, we could specify the pre/post conditions of this message. How strongly this can be expressed in code depends on the programming language.

At any rate, for me, this is how it works. I don't use UML or any kind of notation to design my classes. I do it in code. I may sit down and draw out a state transition diagram for a class. But that's about it. Received on Wed Apr 09 2008 - 17:30:31 CEST

Original text of this message