-
Notifications
You must be signed in to change notification settings - Fork 0
/
polymorphism_birds.py
70 lines (61 loc) · 1.75 KB
/
polymorphism_birds.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
""" A play at Polymorphism
NOTE: The word polymorphism derives from Greek meaning “something that takes
many forms.” In object-oriented programming, polymorphism allows objects of
different types, each with their own specific behaviors, to be treated as the
same general type.
"""
class Bird(object):
""" Abstaract Class """
def __init__(self, weight):
""" (Bird, float) -> stdout, Bird
Init
"""
print('__init__ of Bird class called.')
self.__weight = weight
def get_weight(self):
""" (Bird) -> str
Return Bird object weight
"""
return '{0} ounces'.format(self.__weight)
def get_color(self):
""" (Bird) -> Exception
Abstract Method
"""
raise NotImplementedError('Method color not Implemented')
class BlueJay(Bird):
""" Subclass of Bird class """
def __init__(self, weight):
""" (BlueJay, float) -> Bird
Init
"""
Bird.__init__(self, weight)
def get_color(self):
""" (BlueJay) -> str
Returns Bird's color
"""
return 'Blue'
class Cardinal(Bird):
""" Subclass of Bird class """
def __init__(self, weight):
""" (Cardinal, float) -> Bird
Init
"""
Bird.__init__(self, weight)
def get_color(self):
""" (Cardinal) -> str
Returns Bird's color
"""
return 'Red'
class BlackBird(Bird):
""" Subclass of Bird class """
def __init__(self, weight):
""" (BlackBird, float) -> Bird
Init
"""
Bird.__init__(self, weight)
def get_color(self):
""" (BlackBird) -> str
Returns Bird's color
"""
return 'Black'