面向对象编程特点

面向对象编程特点

  1. Everything is an object . Think of an object as a fancy variable; it stores data,
    but you can “make requests” to that object, asking it to perform operations on itself. In
    theory, you can take any conceptual component in the problem you’re trying to solve
    (dogs, buildings, services, etc.) and represent it as an object in your program.
    所有东西都是一个对象。 试着把对象想想成一个可变的变量;它可以存储数据,但是你可以通过请求的方式,让它执行一些它的操作。在理论上,你可以把需要解决的问题中所有东西看成一个对象,比如dogs, buildings, services等等.
  2. A program is a bunch of objects telling each other what to do by
    sending messages. To make a request of an object, you “send a message” to that
    object. More concretely, you can think of a message as a request to call a method that belongs to a particular object.
    一个程序是一群对象组合起来,互相说自己可以通过接受信息做些什么。通过发送信息,去请求一个对象。更具体的说,你可以认为信息是一个对于特别对象所属方法的请求。
  3. Each object has its own memory made up of other objects. Put another way, you create a new kind of object by making a package containing existing objects. Thus, you can build complexity into a program while hiding it behind the simplicity of objects.
    所有对象都有自己的由其他对象组成的内存。从另一个角度来说,你创建一个新的类型的对象,通过将现存的对象组合起来。这样你可以简单的编程,把复杂的东西隐藏起来。
  4. Every object has a type. Using the parlance, each object is an instance of a
    class, in which “class” is synonymous with “type.” The most important distinguishing characteristic of a class is “What messages can you send to it?”
    所有对象拥有一个类型。在这种看来,一个对象都是一个class的实例化对象,而class也是type的同义词。Class之间最重要的区别是你应该如何给它传送信息。
  5. All objects of a particular type can receive the same messages. This
    is actually a loaded statement, as you will see later. Because an object of type “circle” is also an object of type “shape,” a circle is guaranteed to accept shape messages. This means you can write code that talks to shapes and automatically handle anything that fits the description of a shape. This substitutability is one of the powerful concepts in OOP.
    如果多个对象同属一个特别的类型,那么它们可以接受相同的信息。这个从实际上来说,是一个加载语句,你将在以后看到。因为一个圆圈的对象,实际上也是shape的一个对象,一个circle对象保证了可以接受shape的消息。这意味着你编写适用于shape的code可以自动满足任何同时满足shape的对象。这个可替代性是OOP一个很重要的观念。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值