1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| class Entity: def __init__(self, object_type): print('parent class init called') self.object_type = object_type
def get_context_length(self): raise Exception('get_context_length not implemented')
def print_title(self): print(self.title)
class Document(Entity): def __init__(self, title, author, context): print('Document class init called') Entity.__init__(self, 'document') self.title = title self.author = author self.__context = context
def get_context_length(self): return len(self.__context)
class Video(Entity): def __init__(self, title, author, video_length): print('Video class init called') Entity.__init__(self, 'video') self.title = title self.author = author self.__video_length = video_length
def get_context_length(self): return self.__video_length
harry_potter_book = Document('Harry Potter(Book)', 'J. K. Rowling', '... Forever Do not believe any thing is capable of thinking independently ...') harry_potter_movie = Video('Harry Potter(Movie)', 'J. K. Rowling', 120)
print(harry_potter_book.object_type) print(harry_potter_movie.object_type)
harry_potter_book.print_title() harry_potter_movie.print_title()
print(harry_potter_book.get_context_length()) print(harry_potter_movie.get_context_length())
|