-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Robert schreef:
| Lew a écrit :
|> Tom Anderson wrote:
|>> The question here is what this method *should* do if given an
|>> instance of a class other than A or B. If the answer is "that can't
|>> happen, it's always A or B", then throwing an exception is the only
|>> right thing to do, because it signals that something impossible has
|>> happened. If it's the case that other classes are, or might one day
|>> be, possible here, then having a sensible default and special-casing
|>> the classes which need it is not a bad idea.
|>>
|>> Of course, in this particular situation, you should really be using
|>> polymorphism, not an if-else cascade, but this is an example for the
|>> sake of argument, so never mind.
|>
|> Actually, if the only reason you're throwing an exception is that
|> you're using explicit run-time type tests, instead of relying on
|> object-oriented programming and compile-time checking, then you have a
|> deeper problem than whether you should silently eat and ignore
|> exceptions.
|>
|> That example actually shows that one should not be testing for type
|> explicitly, or else one is stuck with handling an exception that
|> shouldn't even be possible. Using polymorphism as Tom suggests
|> obviates the entire problem.
|>
|> As an example of whether one should throw exceptions it totally fails,
|> because it relies on a scenario that one should prevent in the first
|> place.
|>
|
| Do you think having an overrided method with return a constant Point
| object worth it ?
|
| Don't you think it makes the original method harder to read ?
Why don’t you give an example. Such questions are hard to answer and
differ from case to case. In general I’d say: no, since I assume you
(or the casual reader of the code) know how the overriding mechanism
works and as such can easily understand what is going on.
H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE -
http://enigmail.mozdev.org
iD8DBQFITQPJe+7xMGD3itQRAomyAJ9NnNkrqrJX992xlIQZYA8NUqjNSQCeLjYF
WddvKSa+CLwDq/ysFtAqw7I=
=PxU1
-----END PGP SIGNATURE-----