Code in Python Please!!! Topics: Inheritance, exceptions, and polymorphism Demonstrate that you understand exceptions, i
Posted: Mon Jun 06, 2022 6:48 pm
Code in Python Please!!!
Topics: Inheritance, exceptions, and polymorphism
Demonstrate that you understand exceptions, inheritance, and the
idea of polymorphism, how they are designed, and how they are
handled
First, start with a design:
Pick a generic object where something could cause exception in
its state (example: parts breaking on a vehicle),
Describe a generic exception that could happen in your object
(example: BrokenVehiclePartError),
Describe two subclasses of the object (examples: car and truck,
boat and starship, boat and bike),
Describe two subclasses of the exception (examples: flat tire,
busted hitch, reactor coolant leak)
Draw an inheritance diagram that shows the relationships between
the various classes and the exceptions.
Design a program that uses your classes and inheritance diagram
showing how inheritance can work.
(this could be something like a car sales lot, a mechanics shop, or
a racing “game”, allowing you to interact with the objects or
components, causing exceptions to occur, and handling those
exceptions)
Next, implement your design:
Implement your design in a simple program showing:
classes working properly (just print their valid values and
such),
exceptions being raised, caught, and handled,
an exception that does not get handled that crashes your program
(save this part for last in your program please!).
Print the data in an organized way, being sure to show the whole
list of instances that could be in a given classification.
What kinds of tests would be useful for this? How could we
test some of it to verify that it was working properly?
Implement some of those tests in PyTest!
Topics: Inheritance, exceptions, and polymorphism
Demonstrate that you understand exceptions, inheritance, and the
idea of polymorphism, how they are designed, and how they are
handled
First, start with a design:
Pick a generic object where something could cause exception in
its state (example: parts breaking on a vehicle),
Describe a generic exception that could happen in your object
(example: BrokenVehiclePartError),
Describe two subclasses of the object (examples: car and truck,
boat and starship, boat and bike),
Describe two subclasses of the exception (examples: flat tire,
busted hitch, reactor coolant leak)
Draw an inheritance diagram that shows the relationships between
the various classes and the exceptions.
Design a program that uses your classes and inheritance diagram
showing how inheritance can work.
(this could be something like a car sales lot, a mechanics shop, or
a racing “game”, allowing you to interact with the objects or
components, causing exceptions to occur, and handling those
exceptions)
Next, implement your design:
Implement your design in a simple program showing:
classes working properly (just print their valid values and
such),
exceptions being raised, caught, and handled,
an exception that does not get handled that crashes your program
(save this part for last in your program please!).
Print the data in an organized way, being sure to show the whole
list of instances that could be in a given classification.
What kinds of tests would be useful for this? How could we
test some of it to verify that it was working properly?
Implement some of those tests in PyTest!