should error class be defined in the class it logically belongs?

Z

Zhang Weiwu

Let's say we have in livestocks.py

# livestocks.py stores all livestock classes
class cat()
...

class Dog()
...

class CanineDistemper(Exception)
'''
<<< Buddy = Dog(name = "Buddy")
<<< raise CanineDistemper(Buddy) # horrible test code!
'''
def __init__(self, dog)
self.owner = dog # a specific dog
def __str__(self)
return "{} has had Canine Distemper".format(self.canine)

One would naturally wonder, since

1. by definition only a canine (a dog) can have CanineDistemper, and
2. in no case can CanineDistemper be raised without specifying which object
(canine) is having the problem,

Thus, CanineDistemper is an integral part of Canine class, and one is
naturally tempted to defined CanineDistemper inside Canine class.

Let some experienced OOP guy explain a bit if this line of thinking is
logical, or impratical. Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top