Python学习笔记(三十)- 类的设计(Designing with Classes)

1.什么是多重继承(multiple inheritance)?
答:.当一个类继承自多个超类时,会发生多重继承;它可以将多个基于类的代码包混合在一起。类语句头中的从左到右的顺序决定了属性搜索的一般顺序。

2.什么是委托(delegation?)?
答:委托涉及将对象包装在代理类中,这会增加额外的行为并将其他操作传递给被包装的对象。代理保留包装对象的接口。

3.什么是组合(composition?)?
答:组合是一种技术,将控制器类嵌入并引导多个对象,并提供自己的接口;这是一种用类构建更大结构的方法。

4.什么是约束方法(bound methods)?
答:约束方法结合实例和方法的函数;您可以在不显式传递实例对象的情况下调用它们,因为原始实例仍然可用。

5.什么是伪私人属性(pseudoprivate attributes)?
答:伪私人属性(名称两个双下划线作为开头但不作为结尾:__ X)用于将名称局部化为封闭类。这包括类属性,如类中定义的方法,以及在类的方法内赋值的self实例。这些名称被扩展为包括类名,这使它们通常是唯一的。

 

inheritance(继承) composition(组合) delegation(委托) factories(工厂)

 

注:转载《Learning Python 5th Edition》[奥莱理]
1. What is multiple inheritance?
2. What is delegation?
3. What is composition?
4. What are bound methods?
5. What are pseudoprivate attributes used for?


1. Multiple inheritance occurs when a class inherits from more than one superclass; it's useful for mixing together multiple packages of class-based code. The left-toright order in class statement headers determines the general order of attribute searches.
2. Delegation involves wrapping an object in a proxy class, which adds extra behavior and passes other operations to the wrapped object. The proxy retains the interface of the wrapped object.
3. Composition is a technique whereby a controller class embeds and directs a number of objects, and provides an interface all its own; it's a way to build up larger structures with classes.
4. Bound methods combine an instance and a method function; you can call them without passing in an instance object explicitly because the original instance is still available.
5. Pseudoprivate attributes (whose names begin but do not end with two leading underscores: __X) are used to localize names to the enclosing class. This includes both class attributes like methods defined inside the class, and self instance attributes assigned inside the class's methods. Such names are expanded to include the class name, which makes them generally unique.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值