All of the previous lessons

本文介绍了传统编程与面向对象编程(OOP)的区别,解释了OOP如何通过整合数据和操作数据的方法来模拟现实世界中的对象,使得程序设计更加直观且模块化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

All of the previous lessons up to this point have one thing in common — they have been non-object-oriented. Now that you have a basic handle on those concepts, we can proceed into object-oriented programming (OOP), where the real payoff is!

In traditional programming, programs are basically lists of instructions to the computer that define data and then work with that data. Data and the functions that work on that data are separate entities that are combined together to produce the desired result.

So what is object-oriented programming? As with so many things, it is perhaps understood most easily through use of an analogy. Take a look around you — everywhere you look are objects. Most objects have two major components to them: 1) A list of properties (eg. weight, color, size, texture, etc…), and 2) Some number of actions that either they can perform, or that can be performed on them (eg. being opened, having something poured into it, etc…). These two components are inseparable.

With traditional programming, the properties (data) and actions (functions) are separate entities, which means that traditional programming often does not provide a very intuitive representation of reality. We are intuitively used to thinking about things as objects, and expect to be able to perform actions with or on those objects.

Object-oriented programming (OOP) provides us with the ability to design “objects” that have both characteristics (sometimes called attributes, fields, or properties) and behaviors (methods or features), all tied together in one package. This allows programs to be written in a more modular fashion, which makes them easier to write and understand, and also provides a higher degree of code-reusability. Objects provide a more intuitive way to work with our data by allowing us to define how we interact with the objects, and how they interact with other objects. Object-oriented programming also brings several other useful concepts to the table: inheritance, encapsulation, abstraction, and polymorphism (language designers have a philosophy: never use a small word where a big one will do).

We will be covering all of these concepts in the upcoming tutorials over the next few chapters. It’s a lot of new material, but once you’ve been properly familiarized with OOP, you’ll never want to go back to traditional programming again.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值