Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PYTHON CODE PLS Case Study ll: Software Engineering with Abstract Classes and Abstract Methods Abstract Base Class PatientThe Python Standard Library's abc (abstract base class)
PYTHON CODE PLS
Case Study ll: Software Engineering with Abstract Classes and Abstract Methods Abstract Base Class PatientThe Python Standard Library's abc (abstract base class) module helps you Concrete Classes-If Circle, Square and Triangle objects all have drawn methods, it's reasonable to define abstract classes by inheriting from the module's ABC class. Your abstract base class Patient class expect that calling draw on a Circle will display a Circle, calling draw on a Square will display a Square and calling draw on a Triangle will display a Triangle. Objects of each class know all the details of the should declare the methods and properties that all patients should have. and a Social Security number. Also, every patientshould have payment method, but the specific and that can be used to create objects are called concrete classes. calculation depends on the patient's type, so you'll make payments an abstract method that the Abstract Classes-Now, let's consider class TwoDimensionalshape in the Shape hierarchy's second subclasses must override. Your Patient class should contain: level. If we were to create a TwoDimensionalshape object and call its draw method, class i. An _init_ method that initializes the first name, last name and Social Security number data TwoDimensionalshape knows that all two-dimensional shapes are drawable, but it does not know attributes. what specific two-dimensional shape to draw-there are many! So, it does not make sense for ii. Read-only properties for the first name, last name and Social Security number data attributes. TwoDimensionalShape to fully implement a draw method. A method that is defined in a given class, iii. An abstract method payment preceded by the abc module's @abstractmethod decorator. but for which you cannot provide an implementation is called an abstract method. Any class with an Concrete subclasses must implement this method. The Python documentation says you should abstract method has a "hole"-the incomplete method implementation-and is called an abstract raise a NotimplementedError in abstract methods. class. TypeErrors occur when you try to create objects of abstract classes. In the Shape hierarchy, iv. A _repr_ method that returns a string containing the first name, last name and Social classes Shape, TwoDimensionalshape and ThreeDimensionalshape all are abstract classes. They all Security number of the patient. know that shapes should be drawable, but do not know what specific shape to draw. Abstract base classes are too general to create real objects. Concrete Subclass RegularPatient-This Patient subclass should override payments to return a Inheriting a Common Design-An abstract class's purpose is to provide a base class from which RegularPatient's weekly payment. The class also should include: subclasses can inherit a common design, such as a specific set of attributes and methods. So, such i. An _init_ method that initializes the first name, last name, Social Security number and classes often are called abstract base classes. In the Shape hierarchy, subclasses inherit from the weekly salary data attributes. The first three of these should be initialized by calling base class abstract base class Shape the notion of what it means to be a Shape-that is, common properties, such as location and color, and common behaviors, such as draw, move and resize. ii. A read-write weekly_payment property in which the setter ensures that the property is always Polymorphic Cost of a Patient System-Now, let's develop an Patient class hierarchy that begins with non-negative. an abstract class, then use polymorphism to perform cost calculations for objects of two concrete iii. A_repr__method that returns a string starting with ' RegularPatient:' and followed by all the subclasses. Consider the following problem statement: information about a RegularPatient. This overridden method should call Patient's version. 1. A patient pays to the healthcare institution weekly. The patients are of two types: i) Regular InstantPatient's payments, based on the hours passed and payment per hour. The class also should patients pay a fixed weekly payment regardless of the number of hours passed in the healthcare include: institution. Instant patients pay by the hour and in addition to an overtime pay (1.5 times their hourly payment rate) for all hours passed in excess of 40 hours in a week. The healthcare institution i. An_init_ method to initialize the first name, last name, Social Security number, hours and wants to implement an app that performs its income calculations polymorphically. payment data attributes. The first name, last name and Social Security number should be initialized by calling base class Patient's _ init _ method. Patient Hierarchy Class Diagram-The following diagram shows the Patient hierarchy. Abstract class ii. Read-write hours and payment properties in which the setters ensure that the hours are in Patient represents the general concept of a patient. Subclasses RegularPatient and InstantPatient range (0-168) and payment per hour is always non-negative. inherit from Patient. iii. A _repr__ method that returns a string starting with InstantPatient:' and followed by all the information about a InstantPatient. This overridden method should call Patient's version. Testing Your Classes In an IPython session, test your hierarchy: 1. Import the classes Patient, RegularPatient and InstantPatient. 2. Attempt to create a Patient object to see the TypeError that occurs and prove that you cannot create an object of an abstract class. 3. Assign objects of the concrete classes RegularPatient and InstantPatient to variables, then display each patient's string representation and payments. 4. Place the objects into a list, then iterate through the list and polymorphically process each object, displaying its string representation and payments
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started