文件名称:
五分钟理解元类(Metaclasses)
开发工具:
文件大小: 325kb
下载次数: 0
上传时间: 2019-03-17
详细说明:NULL
博文链接:https://swingfly.iteye.com/blog/540835Meta-classes are about meta-programming
Programming where the clients are programmers
Language development(e. g. python-dev crowd)
Library/framework development(e. g Zope Corp)
Enabling new metaphors/approaches for programming
Aspect-oriented Interface-oriented Prototype-based
Creating natural programming patterns for end-programmers
Generally created for use within an application domain
Programming with the resulting classes maps between
Python and domain semantics closely
Generality and uniformity
Meta-programming goals
Allows end-programmers to use standard Python programming
features
Leverage existing end-programmer's Python knowledge
Domain-specific features feel "built-in, not bolted on
End-programmer should be able to use declarative
approach in defining classes
this is a that,, not register this as a that
Integrates nicely with other Python systems, introspection,
pickling, properties
Works to simplify and beautify aPis
Meta-classes facilitate meta-programming
In general, there's nothing you can't do some other way
Factory classes
Client classes coded to use a stand-in object in a class-like
manner from which end-programmers must derive
Function-calls to post-process classes after they are created
Other function calls to register features with the system
Meta-classes just make it easier and more elegant
Theyre the basis of Python 2.2+'s type system, so theyre
standard and reliable
There are two things you can't do any other way, meta
methods and meta-properties(more on those later)
That's great and all, but what are they good for
Let's see
What can you do with them? Class registration
In"Aspect-oriented programming
Automate registration of join-points and aspects from
declarative structures and introspection
Look up aspects at run-time from system registries and
encode directly in business-domain classes
In Interface-oriented programming
Register utilities, services, interfaces and adapters
n a more general sense, you can automatically register
information about an end-programmer's classes at the time the
class is created
Class registration example
e In Aspect-oriented programming, every end-user-class's
methods and properties need to be registered with the system
to allow for matching"join points,(features )with"cuts?and
aspects(choke-points and reactive code
You could force the end-programmer to make a call
system register(myclass) for every class, but the point is
that every aspect-oriented class be registered, so you've got
pointless busy-work, and lots of opportunities for failure
register the resulting class for aspect-oriented servicing" o
You want to say"when someone sub-classes Aspectawat
(Similar requirements with registering adapters for interface
oriented programming)
What can you do with them? Class verification
Automated constraints and class-checking
nterface-checking for interface-based programming
Check for internal coherence in the face of end-programmer
errors
Warped things such as creating final classes(classes which
complain when an attempt is made to sub-class them)
In a more general sense, you can check end-programmer's
classes for conformance to any pattern required by your
systems
Class verification example
In Interface-oriented programming, each class declares a set of
inter faces that it provides
During development, you want to automatically check every
interface-aware class for conformance to its published
interfaces(including those created by end-programmers)
You could(have the end-programmer) call
verifylnterfaces( classObject
It's something the end-programmer can easily forget, so there's
no guarantee that all interface-aware classes have been checked
You want to say when someone sub-classes ' InterfaceAware
check the resulting class's interface declarations
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.