Implementing ABCs in Client Objects
00:00
This lesson is just a quick refresher where you will implement what you have learned about abstract base classes so far to the client’s objects, Song
and Book
.
00:12
So in step one, you create an abstract base class for the client objects, and then in step two you have the Song
and Book
classes inherit from the abstract base class.
00:25 So in your code at the very top, create an abstract class.
00:32
Now I’ve called that class ClientObjectBluePrint
.
00:36
And that class, as you know, needs to inherit from ABC
to make it an abstract class. Use the decorator @abstractmethod
to decorate the methods that you would like to enforce.
00:50
And in your case, that is going to be the only method that the Song
and Book
classes are using and that is use_product
.
00:59
And that method takes self
as an input parameter and it doesn’t do anything. It is just there to define the method.
01:08
In step two, you now need to make sure that classes Song
and Book
inherit from ClientObjectBluePrint
. So I’m going to go to line six and copy that long word.
01:21
Go to line 13, open brackets, and paste in ClientObjectBluePrint
. So now the Song
class inherits from the blueprint, and then move down to line 25 and do the same thing for Book
, open brackets, and paste the ClientObjectBluePrint
.
01:40 So with the class structure now all taken care of, in the next lesson you’ll introduce a new data format. So we had JSON, we had XML. In the next lesson you’ll introduce YAML.
Become a Member to join the conversation.