码迷,mamicode.com
首页 > 编程语言 > 详细

Python之多态案例

时间:2019-11-20 19:50:40      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:pytho   span   col   can   triangle   案例   nbsp   sha   style   

 

class Canvas:
    def draw_pic(self, shape):
        print(--start draw--)
        shape.draw(self)

class Rectangle:
    def draw(self, canvas):
        print(draw rectangle on %s % canvas)

class Triangle:
    def draw(self, canvas):
        print(draw triangle on %s % canvas)

class Circle:
    def draw(self, canvas):
        print(draw circle on %s % canvas)

c = Canvas()
c.draw_pic(Rectangle())
c.draw_pic(Triangle())
c.draw_pic(Circle())

 

 

谢谢!

Python之多态案例

标签:pytho   span   col   can   triangle   案例   nbsp   sha   style   

原文地址:https://www.cnblogs.com/zhzhang/p/11899745.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!