From the course: Python Object-Oriented Programming
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Solution: Stocks and bonds - Python Tutorial
From the course: Python Object-Oriented Programming
Solution: Stocks and bonds
(upbeat music) - [Instructor] All right, let's review my solution to this challenge. For this challenge, we needed to create a class hierarchy to represent both stocks and bonds and use inheritance along with an abstract base class. So in my code, I used the asset base class to hold the price property, which is common to both stock and bond objects. And then I have the stock and bond class definitions. They use the asset class as their parent class, and they define their own properties for the specific information to that type of asset. So for stocks, we have the ticker symbol and the company name. For bonds, we have the name, duration, and interest rate. And we also needed to make sure that the asset class itself could not be instantiated, and we needed to require that subclasses override the get description function. So that calls for using an abstract base class with an abstract method. And you can see up here I've imported both ABC, and abstract method from the ABC module, asset…