Command Object In this program the command object is AnImageAnimationCommand A command objects implements Runnable Contains method run Thread need an instance of it to do work ID: 590311
Download Presentation The PPT/PDF document "Thread and Assertion" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
Thread and AssertionSlide2
Command Object
In
this program
the command object
is
AnImageAnimationCommand
A
command objects implements
Runnable
Contains method run()
Thread need
an
instance
of it to
do workSlide3
demo method in
AScene
Creates 2 threads to control the thief and policeman separately.
start() method starts a thread
Demo method will not wait for a thread. It will execute next line immediately.
stop() method terminates a thread. It may cause some catastrophic synchronization problems. So generally it is not good to use stop().Slide4
Assertion
In
AScene
,
a precondition
is used to control whether
to display
thief or
not (whether to let
ObjectEditor
call
getThief
()).
Assertion is in method
getThief
() and
uses the precondition is defined in method
preGetThief
();
Notice that in
propertyChange
method
,
the flag
thiefExist
is set to be false if policeman reaches the thief, and then causes the
precondition for
getThief
() to be false
.
In this program,
this
will
fire property change
notification alerting
ObjectEditor
to the fact that the
preCondition
changed.
ObjectEditor
will no longer call
getThief
.
For
postcondition
, check the code of
AnAssertingBMISpreadsheet
in package
assertionExample
, in
setHeight
.