php opp 面向对象,追溯面向对象(OPP)发展历史

4a38974bc58b0791d17cef622e805f04.png

1. 面向对象的概念

Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data, in the form of fields (often known as attributes or properties), and code, in the form of procedures (often known as methods). A feature of objects is an object's procedures that can access and often modify the data fields of the object with which they are associated (objects have a notion of "this" or "self"). In OOP, computer programs are designed by making them out of objects that interact with one another. OOP languages are diverse, but the most popular ones are class-based, meaning that objects are instances of classes, which also determine their types.

Many of the most widely used programming languages (such as C++, Java, Python, etc.) are multi-paradigm and they support object-oriented programming to a greater or lesser degree, typically in combination with imperative, procedural programming. Significant object-oriented languages include Java, C++, C#, Python, PHP, JavaScript, Ruby, Perl, Object Pascal, Objective-C, Dart, Swift, Scala, Common Lisp, MATLAB, and Smalltalk.

【译】 面向对象程序设计(英语:Object-oriented programming,缩写:OOP)是种具有物件概念的程式编程典范,同时也是一种程序开发的抽象方针。

它可能包含资料、属性、程式码与方法。对象则指的是类的实例。它将对象作为程序的基本单元,将程序和数据封装其中,以提高软件的重用性、灵活性和扩展性,物件里的程序可以访问及经常修改物件相关连的资料。在物件导向程式编程里,电脑程式会被设计成彼此相关的物件。

2. OOP发展历史

用一张脑图介绍OPP发展历史,脑图内容来自 维基百科d32edfd9972b7f57cdd986f2d054c5ac.png

3. JavaScript面向对象设计

在面向对象发展历史中,我们看到从面向对象这一概念衍生出很多种语言,接下来我想首先从JavaScript这门语言的角度去介绍面向对象

3.1. JavaScript的概念

JavaScript often abbreviated as JS, is a programming language that conforms to the ECMAScript specification.JavaScript is high-level, often just-in-time compiled, and multi-paradigm. It has curly-bracket syntax, dynamic typing, prototype-based object-orientation, and first-class functions. 【译】JavaScript通常缩写为JS,是一种编程语言符合的ECMAScript的规范。JavaScript是高级的,通常是即时编译的,并且是多范例的。它具有花括号语法,动态类型,基于原型的面向对象和函数式编程。

ECMA-262 把对象定义为:“无序属性的集合,其属性可以包含基本值、对象或者函数。”严格来讲,

这就相当于说对象是一组没有特定顺序的值。对象的每个属性或方法都有一个名字,而每个名字都映射

到一个值。正因为这样(以及其他将要讨论的原因),我们可以把 ECMAScript(它是JavaScript的标准) 的对象想象成散列表:无非就是一组名值对,其中值可以是数据或函数。

3.2. JavaScript发展历史

以下JavaScript 的发展历史:8788566e0b2a0decdf8ad37879b3bfbc.png

3.3. JavaScript 的面向对象设计

下面是JavaScript 的面向对象设计(

脑图内容来自《JavaScript高级程序设计》)fb1b3d73e719c3653c0de426fd610ee2.png

4. TypeScript面向对象设计

4.1. TypeScript 的概念

上面我们了解到 JavaScript 对象设计的类概念和其他的并不完全一样,接下来我将介绍TpyeScript这门语言,比如从Angular2+、VSCode 开始,就是基于 TypeScript语言写的,TypeScript 是 JavaScript 的超集。

TypeScript is an open-source programming language developed and maintained by Microsoft. It is a strict syntactical superset of JavaScript, and adds optional static typing to the language.

TypeScript is designed for development of large applications and transcompiles to JavaScript.As TypeScript is a superset of JavaScript, existing JavaScript programs are also valid TypeScript programs. TypeScript may be used to develop JavaScript applications for both client-side and server-side execution (as with Node.js or Deno). 【译】TypeScript是Microsoft开发和维护的一种开放源代码 编程语言。它是一个严格语法是JavaScript的超集,并增加了可选的静态类型的语言。

TypeScript是为开发大型应用程序而设计的,并可以编译为JavaScript。由于TypeScript是JavaScript的超集,因此现有的JavaScript程序也是有效的TypeScript程序。TypeScript可以用于开发JavaScript应用程序,以用于客户端和服务器端执行(与Node.js或Deno一样)。

4.2. TypeScript的发展历史

TypeScript于2012年10月首次公开(版本为0.8),TypeScript起源于JavaScript在Microsoft及其外部客户中开发大型应用程序的缺点。处理复杂的JavaScript代码带来的挑战导致需要自定义工具来简化语言组件的开发,TypeScript开发人员寻求一种不破坏与该标准及其跨平台支持的兼容性的解决方案。1c5b76084f02007b56795dba201789f7.png

4.3. TypeScript的面向对象设计

TypeScript 是一门面向对象编程,它的特征如下:

Compatibility with JavaScript(与JavaScript兼容)

Type annotations(类型注释件)

Declaration files(声明文件)

Classes(类)

Generics(泛型)

Modules and namespaces(模块和名称空间)

参考资料

感谢您的阅读

如果文章中有不对的地方,烦请及时指出来,以免误导其他的读者,感谢!

2f2458c105f6ec58cd65f8b495aaf536.png

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值