23.10.2010 4:04, Bob Kerns пишет:
Because you're left with two dead birds instead of one?
Or a ragout made out of two pigeons and marshmallows :) Perhaps pretty,
but inedible.
Runnable is an interface for packaging code into an object. There is
nothing about threading inherent in Runnable.
Having Thread implement Runnable makes using as a Runnable pretty
obvious - and wrong. The entire reason for Thread class's existence is
to be able to run code on a separate thread. That's clearly not the same
as packaging code into an object, which is what Runnable does.
So I'd say this is a case of inheritance for convenience of
implementation, which is usually considered to be a bad. But it's worse
than that, since treating Thread as a Runnable - as permitted by its
derivation - causes Thread to completely break.
Could have been something like this:
class Thread /* does not implement Runnable */
{
// supply runnable to do background work
Thread(Runnable r) {
this.runnable = r;
}
// override worker() to do background work
Thread() {
}
void start ()
{
// fork, call worker()
}
void worker() {
if (this.runnable != null) {
this.runnable.run();
}
else {
throw new IllegalStateException("Either use Thread(Runnable) or override
worker()");
}
}
}
--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en