-
Notifications
You must be signed in to change notification settings - Fork 0
/
abcmetaclasses.py
56 lines (44 loc) · 1.21 KB
/
abcmetaclasses.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
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 15 18:15:28 2016
@author: Ken
"""
from abc import ABCMeta, abstractmethod
class Pet(object):
__metaclass__ = ABCMeta
def __init__(self,name):
self.name = name
@abstractmethod
def can_swim(self):
pass
@abstractmethod
def speak(self):
pass
class Dog(Pet):
def can_swim(self):
super(Dog, self).can_swim()
return True
def speak(self):
super(Dog, self).speak()
return self.name + ' says "Woof!"'
class Cat(Pet):
def can_swim(self):
super(Cat, self).can_swim()
return False
def speak(self):
super(Cat, self).speak()
return self.name + ' says "Meow!"'
class Fish(Pet):
def can_swim(self):
super(Fish, self).can_swim()
return True
def speak(self):
super(Fish, self).speak()
return self.name + " can't speak."
class Plant(Pet):
def can_swim(self):
super(Plant, self).can_swim()
return False
def speak(self):
super(Plant, self).speak()
return self.name + " can't speak."