Re: Client/Service relationships & Flow of Requirements.
- From: AndyW <a@xxxxxxxxxx>
- Date: Thu, 01 Feb 2007 10:59:20 +1300
On Wed, 31 Jan 2007 14:26:28 GMT, "Daniel T." <daniel_t@xxxxxxxxxxxxx>
wrote:
"H. S. Lahman" <h.lahman@xxxxxxxxxxx> wrote:
Responding to Daniel T....
However, I changed my tune when I started using messages to inform an
object of external conditions, rather than using it to produce wanted
output. Then I ended up with a service that has methods which must be
called when particular external conditions are met. That's something
that doesn't fit well with DbC nor with HS' remarks. When using messages
in this way, changes in the service can force client changes.
I don't see why there would be a problem. [Of course I use object state
machines for /all/ behavior responsibilities so my behaviors are
/always/ triggered by events announcing changes in external conditions.
B-)] Do you have an example that demonstrates the problem?
The basic assumption in the "client owns the interface" principle is
that the client needs the service to perform some action on its behalf.
Obviously the client must be able to inform the service when to perform
that action, so the client gets to add methods to the interface
describing the services it needs. However, when messages are used to
inform, rather than compel, the onus is on the message sender to do the
informing.
The predator/prey example can serve to illustrate what I mean:
The following is designed to compel Prey objects to do something:
class Prey:
def runFrom( predator ):
require: predator < 100 yards from prey
ensure: predator > 100 yards from prey
Whatever code sends the "runFrom" message to prey objects, it expects a
particular result, it is specifically sending the message so that the
prey will move away from the predator. (I.E., to cause the state to
change such that the predator and prey are more than 100 yards away from
each-other.) There is no requirement on the client to send the "runFrom"
message if the client doesn't want the prey object to move.
However, if the message is designed to inform rather than compel:
class Prey:
def predatorWithin100yards( predator ):
require: n/a
ensure: n/a
Now, the contract (which can't be stated properly in either the require
or ensure clause) is that anytime a predator is within 100 yards of the
prey object, it shall be informed of that fact. The onus is on the
client to do the right thing. The Prey object need not do anything at
all in response to the message.
Sorry, just to go off on an tangent here (and the following is just
off the top of my head without any real thought)
Consider the structure
class Location: << Mixin>>
x, y, z etc.
class AnimalLocations: << service>>
Locations
CompareLocations
registerObjects
class Animal: << abstract >>
Location
UpdateLocation
detectOtherAnimal
class Preditor : Animal <<concrete abstract>>
sneak, run, pounce, lookforprey
class Prey : Animal <<concrete abstract>>
hide, flee, keepwatchforpreditor
KnightOfCamelot : prey <object>
KillerBunnyOfCaerBannog : Preditor <<object>>
animalLocations.registerObjects( KightOfCamelot,
KillerBunnyOfCaerBannog)
What happens is that in the concurrent model, every animal has a
location. Those locations could be registered in an observable entity
(animal locations). When an animal moves, it needs to publish its new
location [updateLocation].
As each animal moves, it also checks the new location to see if there
is another animal near [DetectOtherAnimal/CompareLocations]. It would
then check to see what type of animal to see if needed to flee or
pounce etc.
Because each animal should be doing this check at the same time, it
becomes a concurrent application. There are different
implementations, thread per animal, thread for service methods etc
(but I am not up to play on concurrent development these days).
The idea behind this example was to try to demonstrate the removal of
messaging and the ability for an object to implement its own
behaviour.
Andy
.
- References:
- Client/Service relationships & Flow of Requirements.
- From: John Carter
- Re: Client/Service relationships & Flow of Requirements.
- From: Daniel T.
- Re: Client/Service relationships & Flow of Requirements.
- From: H. S. Lahman
- Re: Client/Service relationships & Flow of Requirements.
- From: Daniel T.
- Client/Service relationships & Flow of Requirements.
- Prev by Date: UML Activity Diagram - 1 Activity across 2 or more swimlanes
- Previous by thread: Re: Client/Service relationships & Flow of Requirements.
- Next by thread: Re: TDD/BDD and Use cases.
- Index(es):
Relevant Pages
|