Thinking in java-5 Java中对象存在的意义

1.对象简介 Introduction to Objects

The genesis of the computer revolution was in a machine. The genesis of our programming languages thus tends to look like that machine.
But computers are not so much machine as they are mind amplification tools (bicycles for the mind, as Steve Jobs is fond of saying) and a different kind of expressive medium. Object-oriented programming (OOP) is part of the movement toward using the computer as an expressive medium.
面向对象编程(OOP)–是为了让计算机使用起来更像一种表达媒介。

2.对象有接口An object has an interface

Although what we really do in object-oriented programming is to create new data types, virtually (事实上) all object-oriented languages use the “class” keyword. When you see the word “type” think “class” and vice versa.
There needs to be a way to make a request of the object so that it will do something , and each object can satisfy only certain requests. The requests you can make of an object are defined by its interface, and the type is what determines the interface.
The interface determines the requests that you can make for a particular object. However, there must be code somewhere to satisfy the request. This, along with the hidden data, comprises the implementation.

  • 面向对象语言其实是创建了一种新的数据结构,以’class’关键字标识。
  • 对于每个对象而言,都有一种方式请求这个对象做些什么,而且每个对象只能对某一些请求回应。
  • 所能对对象做的请求就是该对象的接口interface.

3. 对象作为服务提供者An object provides services

While you’re trying to develop or understand a program design, one of the best ways to think about the objects is as “service providers”. Your program itself will provide services to the user, and it will accomplish this by using the services offered by the other objects. Your goal is to produce (or even better, locate in existing code libraries) a set of objects that provide the ideal services to solve your problem.
This is a reasonable way to decompose a problem into a set of objects.
Thinking of an object as a service provider has an additional benefit: it helps to improve the coherence (cohesiveness) of the object. High cohesion is a fundamental quality of software design: It means that the various aspects of a software component (such as an object, although this could also apply to a method or a library of objects) “fit together” well.
In a good object-oriented design, each object does one thing well, but doesn’t try to do too much. This not only allows the discovery of objects that may be purchased, but it also produces new objects that might be reused somewhere else.
Treating objects as service providers is a great simplifying tool. This is useful not only during the design process, but also when someone else is trying to understand your code or reuse an object.

  • 当我们进行程序设计时,我们倾向于把对象作为一种“服务提供者”。目标是制造(后者更好的是在现存代码库中找到)一组能提供服务的对象来解决问题。
  • 把对象作为服务提供者的一个附加好处是:能提高对象的内聚程度(coherence)。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值