关闭

面向对象编程特点

标签: 面向对象编程
157人阅读 评论(0) 收藏 举报
分类:

面向对象编程特点

  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

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:105183次
    • 积分:2757
    • 等级:
    • 排名:第14757名
    • 原创:148篇
    • 转载:32篇
    • 译文:24篇
    • 评论:15条
    文章分类
    最新评论