python basis of Chapter XXVII: mixin design pattern

mixin design pattern

mixin design pattern

advantage:

1.mixin design patterns at the content class is not modified premise functionality extension class (parent class added)

2. more convenient to organize and maintain a different form

3. function may need to be adjusted according to the development

4. avoid generating more classes

Disadvantages: subject to inheritance restrictions, it is recommended to use only two of inheritance

Non-mixin pattern # 
# fruit
# class Fruit:
# Pass
# # southern fruit
# class S_Fruit (Fruit):
# Pass
# # northern fruits
# class N_Fruit (Fruit):
# Pass
# # not gifts southern fruit
# class N_gift_S_Ftuit (S_Fruit):
# Pass
#
# # can Gift southern fruit
# class Y_gift_S_Ftuit (S_Fruit):
# Pass
# # gifts can not be north fruits
# class N_gift_N_Ftuit (S_Fruit):
# Pass
# # can Gift northern fruits
# class Y_gift_N_Ftuit (S_Fruit):
# Pass
# # do not Flayer, can give gifts, south fruits
# class N_Bapi_Y_gift_S_Fruit (Y_gift_S_Ftuit, S_Fruit):
# Pass
# # with strips, can be a gift, Southern fruit
# class Y_Bapi_Y_gift_S_Fruit (Y_gift_S_Ftuit, S_Fruit) :
# Pass
# # do not Flayer, can give gifts, northern fruits
# class N_Bapi_Y_gift_N_Fruit (Y_gift_S_Ftuit, S_Fruit):
# Pass
# class the Apple (N_Fruit, Y_gift_N_Ftuit, N_Bapi_Y_gift_N_Fruit):
# Pass


# Minxin design patterns
class N_Fruit ():
Pass
class S_Fruit () :
Pass
class Y_gift ():
Pass
class N_gift ():
Pass
class Y_Bapi ():
Pass
class N_Bapi ():
Pass

class the Apple (N_Fruit, Y_gift, N_Bapi):
Pass

 

Guess you like

Origin www.cnblogs.com/szc-boke/p/11285632.html