~dkuhlman/python-training-materials/Materials

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
#!/usr/bin/env python

"""
synopsis:
    Illustrate use of module abc -- abstract base class.
    This usage pattern controls which classes can and cannot be instantiated.
"""

from abc import ABCMeta, abstractmethod


class A(object):
    __metaclass__ = ABCMeta

    @abstractmethod
    def m1(self):
        print 'hi'


class B(A):
    def m1(self):
        A.m1(self)
        print 'bye'


class C(A):
    def m2(self):
        A.m1(self)
        print 'bye'


def test():
    b = B()
    b.m1()
    print '-' * 50
##     c = C()
##     c.m2()
    a = A()
    a.m1()


test()