mixin设计模式

‘’’
多继承的应用场景
什么是设计模式:
设计模式只是一种开发思想,不是什么固定的格式,是前人好的思想
mixin设计模式:
优点:
1. mixin设计模式可以在不对类的内容进行修改的前提下,扩展类的功能(添加父类)
2. 更加方便的组织和维护不同的组建
3. 可以根据开发需要任意调整功能
4. 可以避免产生更多的类
缺点:
1. 受继承关系的限制,推荐只有两层的继承使用。

‘’’
#创建一个水果类:
class Fruit:
pass

#南方水果类
class SouthFruit(Fruit):
pass

#北方水果类
class NorthFruit(Fruit):
pass

#南方礼物水果
class SouthGiftFruit(Fruit,SouthFruit):
pass

#南方非礼物水果
class SouthNotgiftFruit(Fruit,SouthFruit):
pass

#北方礼物水果
class NorthGiftFruit(Fruit,NorthFruit):
pass

#北方非礼物水果
class NorthNotgiftFruit(Fruit,NorthFruit):
pass

#苹果类
class Apple(Fruit,NorthFruit,NorthGiftFruit):
pass

#梨类
class Pear(Fruit,NorthFruit,NorthNotgiftFruit):
pass

#香蕉类
class Banana(Fruit,SouthFruit,SouthNotgiftFruit):
pass

#橘子类
class Orange(Fruit,SouthFruit,SouthGiftFruit):
pass

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值