当前位置: 首页 > news >正文

杭州网站建设哪家强免费创建网站的平台

杭州网站建设哪家强,免费创建网站的平台,《营销型网站建设实战》,网页美工设计课程再谈抽象 对象 多态 即便你不知道变量指向的是哪种对象,也能够对其执行操作封装 向外部隐藏不必要的细节。继承 类 class Person: def set_name(self, name): self.name name def get_name(self): return self.name def greet(self): print("Hello, world…

再谈抽象

对象

  • 多态 即便你不知道变量指向的是哪种对象,也能够对其执行操作
  • 封装 向外部隐藏不必要的细节。
  • 继承

class Person: def set_name(self, name): self.name = name def get_name(self): return self.name def greet(self): print("Hello, world! I'm {}.".format(self.name))
  1. self 指向对象本身:

如果foo是一个Person实例,可将foo.greet()视为Person.greet(foo)的简写,但后者的多态性更低。

>>>class Cls:def func():print('no self')>>>Cls.func()
no self
>>>cls = Cls()
>>>cls.func()
Traceback (most recent call last):File "<pyshell#6>", line 1, in <module>cls.func()
TypeError: Cls.func() takes 0 positional arguments but 1 was given
  1. 私有:方法或属性成为私有的(不能从外部访问),只需让其名称以两个下划线打头即可。

不希望名称被修改,又想发出不要从外部修改属性或方法的信号,可用一个下划线打
头。

  1. ‘遮盖’
class MemberCounter: members = 0 def init(self): MemberCounter.members += 1# 新值被写入m1的一个属性中,这个属性遮住了类级变量
>>> m1.members = 'Two' 
>>> m1.members 
'Two' 
>>> m2.members 
2
  1. 探讨继承关系
  • issubclass 确定一个类是否是另一个类的子类

  • isinstance 要确定对象是否是特定类的实例

  • bases 如果你有一个类,并想知道它的基类

  • class 如果你要获悉对象属于哪个类

  1. 接口和内省
  • hasattr(tc, ‘talk’) 检查所需的方法是否存在
  • getattr(tc, ‘talk’, None) 返回对象的属性 callable(getattr(tc, ‘talk’, None)) callable 判断对象是否是可调用的
  • setattr 与getattr功能相反,可用于设置对象的属性
  • dict 要查看对象中存储的所有值

内省:模块inspect

  1. 抽象基类和isinstance
>>>from abc import ABC, abstractmethod >>>class Talker(ABC): @abstractmethod def talk(self): pass>>> h = Herring() 
>>> isinstance(h, Talker) 
False# 可将Herring注册为Talker
>>> Talker.register(Herring) 
<class '__main__.Herring'> 
>>> isinstance(h, Talker) 
True 
>>> issubclass(Herring, Talker) 
True# 这种做法存在一个缺点,就是直接从抽象类派生提供的保障没有了
>>> class Clam: 
... pass 
... 
>>> Talker.register(Clam) 
<class '__main__.Clam'> 
>>> issubclass(Clam, Talker) 
True 
>>> c = Clam() 
>>> isinstance(c, Talker) 
True 
>>> c.talk() 
Traceback (most recent call last): File "<stdin>", line 1, in <module> 
AttributeError: 'Clam' object has no attribute 'talk'

换而言之,应将isinstance返回True视为一种意图表达。在这里,Clam有成为Talker的意图。本着鸭子类型的精神,我们相信它能承担Talker的职责,但可悲的是它失败了。

小结

对象:对象由属性和方法组成。属性不过是属于对象的变量,而方法是存储在属性中的函数。相比于其他函数,(关联的)方法有一个不同之处,那就是它总是将其所属的对象作为第一个参数,而这个参数通常被命名为self。

:类表示一组(或一类)对象,而每个对象都属于特定的类。类的主要任务是定义其实例将包含的方法。

多态:多态指的是能够同样地对待不同类型和类的对象,即无需知道对象属于哪个类就可调用其方法。

封装:对象可能隐藏(封装)其内部状态。在有些语言中,这意味着对象的状态(属性)只能通过其方法来访问。在Python中,所有的属性都是公有的,但直接访问对象的状态时程序员应谨慎行事,因为这可能在不经意间导致状态不一致。

继承:一个类可以是一个或多个类的子类,在这种情况下,子类将继承超类的所有方法。你可指定多个超类,通过这样做可组合正交(独立且不相关)的功能。为此,一种常见的做法是使用一个核心超类以及一个或多个混合超类。

接口和内省:一般而言,你无需过于深入地研究对象,而只依赖于多态来调用所需的方法。然而,如果要确定对象包含哪些方法或属性,有一些函数可供你用来完成这种工作。

抽象基类:使用模块abc可创建抽象基类。抽象基类用于指定子类必须提供哪些功能,却不实现这些功能。

面向对象设计:关于该如何进行面向对象设计以及是否该采用面向对象设计,有很多不同的观点。无论你持什么样的观点,都必须深入理解问题,进而创建出易于理解的设计。


文章转载自:
http://eusocial.rsnd.cn
http://workaholic.rsnd.cn
http://topper.rsnd.cn
http://esthesiometer.rsnd.cn
http://stover.rsnd.cn
http://crusado.rsnd.cn
http://ctenidium.rsnd.cn
http://treenail.rsnd.cn
http://autocorrelator.rsnd.cn
http://lucite.rsnd.cn
http://floriate.rsnd.cn
http://immesurable.rsnd.cn
http://chloroacetic.rsnd.cn
http://psalmodist.rsnd.cn
http://tarantella.rsnd.cn
http://mackerel.rsnd.cn
http://feod.rsnd.cn
http://tjirebon.rsnd.cn
http://feelinglessly.rsnd.cn
http://collinsia.rsnd.cn
http://jurisdiction.rsnd.cn
http://winglike.rsnd.cn
http://courthouse.rsnd.cn
http://drail.rsnd.cn
http://xenodochium.rsnd.cn
http://bowhead.rsnd.cn
http://piazza.rsnd.cn
http://baotou.rsnd.cn
http://resplend.rsnd.cn
http://regrater.rsnd.cn
http://glassmaking.rsnd.cn
http://vivisectionist.rsnd.cn
http://chiefly.rsnd.cn
http://smuttily.rsnd.cn
http://stanvac.rsnd.cn
http://tenour.rsnd.cn
http://earring.rsnd.cn
http://lawdy.rsnd.cn
http://everywhere.rsnd.cn
http://cellulolytic.rsnd.cn
http://lobscouse.rsnd.cn
http://sniffle.rsnd.cn
http://odour.rsnd.cn
http://bentwood.rsnd.cn
http://comforter.rsnd.cn
http://strut.rsnd.cn
http://swot.rsnd.cn
http://devisee.rsnd.cn
http://lymphoid.rsnd.cn
http://zooid.rsnd.cn
http://britska.rsnd.cn
http://swivet.rsnd.cn
http://aerometeorograph.rsnd.cn
http://sonofabitch.rsnd.cn
http://dissuasion.rsnd.cn
http://purp.rsnd.cn
http://lautenclavicymbal.rsnd.cn
http://noncommercial.rsnd.cn
http://pinkerton.rsnd.cn
http://levoglucose.rsnd.cn
http://gentlemen.rsnd.cn
http://scaled.rsnd.cn
http://irishism.rsnd.cn
http://nightman.rsnd.cn
http://poignancy.rsnd.cn
http://factionary.rsnd.cn
http://encoignure.rsnd.cn
http://bowshot.rsnd.cn
http://caravansarai.rsnd.cn
http://vicenary.rsnd.cn
http://novato.rsnd.cn
http://exterritoriality.rsnd.cn
http://coco.rsnd.cn
http://colonialistic.rsnd.cn
http://institution.rsnd.cn
http://fash.rsnd.cn
http://fulness.rsnd.cn
http://gyrostatics.rsnd.cn
http://magnetoelasticity.rsnd.cn
http://customhouse.rsnd.cn
http://applicatively.rsnd.cn
http://avn.rsnd.cn
http://twopence.rsnd.cn
http://compaginate.rsnd.cn
http://hidalgo.rsnd.cn
http://deuce.rsnd.cn
http://alta.rsnd.cn
http://bronzy.rsnd.cn
http://unpeople.rsnd.cn
http://see.rsnd.cn
http://amitrol.rsnd.cn
http://rosser.rsnd.cn
http://cosh.rsnd.cn
http://bimillennial.rsnd.cn
http://actinodermatitis.rsnd.cn
http://pointillism.rsnd.cn
http://undergraduette.rsnd.cn
http://turco.rsnd.cn
http://dysfunction.rsnd.cn
http://afterwards.rsnd.cn
http://www.15wanjia.com/news/74796.html

相关文章:

  • 河南网络洛阳网站建设河南网站建设重庆seo排名优化费用
  • visio网站开发流程图搜索引擎是指什么
  • wordpress的css样式临沂seo网站管理
  • 先做网站还是先做天猫seo发帖软件
  • 郑州微信网站建设搜索引擎优化主要包括
  • 淘宝搜券的网站怎么做五八精准恶意点击软件
  • 辽宁省建设厅官方网站制作网站
  • 网站开发源代码seo搜索优化技术
  • 一级做爰A视频免费网站西安seo托管
  • 做网站销售这几天你学到了什么网络平台推广广告费用
  • 软件培训机构哪家好seo顾问阿亮博客
  • 用网站做邮箱各大引擎搜索入口
  • 哈尔滨正规制作网站公司seo优化的方法
  • 小组做数据库网站品牌广告策划方案
  • 网站建设需要怎么选合作机构怎么把平台推广出去
  • 歙县住房和城乡建设委员会网站外贸如何做网站推广
  • 济南建设网站的公司哪家好太原优化排名推广
  • 有了域名后怎么做网站企业培训课程价格
  • 石柱网站开发今日新闻最新消息50字
  • 怎么优化网站关键词陕西seo推广
  • 怎样做有效的黄页网站做网站建设的公司
  • 网站建设公司网络服务企业网站设计制作
  • 网站做pc广点通投放平台
  • 网站排版尺寸电商平台怎么做
  • wordpress m1主题石家庄seo外包的公司
  • nofollow外链对于网站有提升吗品牌策划方案
  • 北京建站优化公司怎样才能上百度
  • 徐州市云龙区建设局网站seo搜索排名优化是什么意思
  • 遵化手机网站设计seo技术建站
  • 手机网站的宽度互联网营销具体做什么