您的位置:首页 > 移动开发 > Objective-C

Thinking in Java 读书笔记 —— 1.Introducation to Object

2005-09-02 00:38 405 查看
Thinking in Java

span.foldopened { color: white; font-size: xx-small;
border-width: 1; font-family: monospace; padding: 0em 0.25em 0em 0.25em; background: #e0e0e0;
VISIBILITY: visible;
cursor:pointer; }
span.foldclosed { color: #666666; font-size: xx-small;
border-width: 1; font-family: monospace; padding: 0em 0.25em 0em 0.25em; background: #e0e0e0;
VISIBILITY: hidden;
cursor:pointer; }
span.foldspecial { color: #666666; font-size: xx-small; border-style: none solid solid none;
border-color: #CCCCCC; border-width: 1; font-family: sans-serif; padding: 0em 0.1em 0em 0.1em; background: #e0e0e0;
cursor:pointer; }
li { list-style: none; }
span.l { color: red; font-weight: bold; }
a:link {text-decoration: none; color: black; }
a:visited {text-decoration: none; color: black; }
a:active {text-decoration: none; color: black; }
a:hover {text-decoration: none; color: black; background: #eeeee0; }

// Here we implement folding. It works fine with MSIE5.5, MSIE6.0 and
// Mozilla 0.9.6.
if (document.layers) {
//Netscape 4 specific code
pre = 'document.';
post = ''; }
if (document.getElementById) {
//Netscape 6 specific code
pre = 'document.getElementById("';
post = '").style'; }
if (document.all) {
//IE4+ specific code
pre = 'document.all.';
post = '.style'; }
function layer_exists(layer) {
try {
eval(pre + layer + post);
return true; }
catch (error) {
return false; }}
function show_layer(layer) {
eval(pre + layer + post).position = 'relative';
eval(pre + layer + post).visibility = 'visible'; }
function hide_layer(layer) {
eval(pre + layer + post).visibility = 'hidden';
eval(pre + layer + post).position = 'absolute'; }
function hide_folder(folder) {
hide_folding_layer(folder)
show_layer('show'+folder);
scrollBy(0,0); // This is a work around to make it work in Browsers (Explorer, Mozilla)
}
function show_folder(folder) {
// Precondition: all subfolders are folded
show_layer('hide'+folder);
hide_layer('show'+folder);
show_layer('fold'+folder);
scrollBy(0,0); // This is a work around to make it work in Browsers (Explorer, Mozilla)
var i;
for (i=1; layer_exists('fold'+folder+'_'+i); ++i) {
show_layer('show'+folder+'_'+i); }
}
function show_folder_completely(folder) {
// Precondition: all subfolders are folded
show_layer('hide'+folder);
hide_layer('show'+folder);
show_layer('fold'+folder);
scrollBy(0,0); // This is a work around to make it work in Browsers (Explorer, Mozilla)
var i;
for (i=1; layer_exists('fold'+folder+'_'+i); ++i) {
show_folder_completely(folder+'_'+i); }
}
function hide_folding_layer(folder) {
var i;
for (i=1; layer_exists('fold'+folder+'_'+i); ++i) {
hide_folding_layer(folder+'_'+i); }
hide_layer('hide'+folder);
hide_layer('show'+folder);
hide_layer('fold'+folder);
scrollBy(0,0); // This is a work around to make it work in Browsers (Explorer, Mozilla)
}
function fold_document() {
var i;
var folder = '1';
for (i=1; layer_exists('fold'+folder+'_'+i); ++i) {
hide_folder(folder+'_'+i); }
}
function unfold_document() {
var i;
var folder = '1';
for (i=1; layer_exists('fold'+folder+'_'+i); ++i) {
show_folder_completely(folder+'_'+i); }
}

All +
All -
Thinking in Java

1.Introducation to Object

+ -
面向对象——抽象

1.你可以把要解决的问题中所有的概念性的组件都当做一个对象

2.程序是一组相互之间传递消息,告诉对方该干什么的对象。

消息,是调用专属于某个对象的方法的请求。

3.

4.任何对象都是某个类的实例

5.所有属于同一个类的对象都可以接受同样的消息

所有对象都有 状态、行为 和 标示

每个对象都属于某个类,而这些类定义它的特征和行为

类描述的是一组有共同特征和行为的对象

类实际上也是一种数据类型

类,是程序员为解决特定问题而定制的

数据类型,是为了表示计算机的存储单元而设计的

对象,是 类 的 实例

每个对象,都是这个类的一个独立的个体

+ -
面向对象——接口

每个对象只能满足某些请求,而对象所能接受的请求,

是由其所属的类定义的接口决定的

接口只负责决定对象所能接受的请求,而对象对

该请求做出的响应,是由“实现”代码完成的

你向对象发送了一个消息(提交了一个请求)

对象会决定如何处置这个消息(执行代码)

Light lt = new Light()

lt.on();

+ -
面向对象——服务

对象——服务的提供者

软件工程师的任务就是制作一组为解决问题提供最佳服务的对象。

在良好的面向对象设计中,一个对象应该只作

一件事,并且做好一件事,而不是作很多事。

良好的面向对象设计应当是高内聚的

+ -
隐藏实现

程序员分类

类的创建者

客户程序员——类的使用者

对类的内部实现进行隐藏,可以避免类内部的敏感部分被误操作

只允许客户程序员通过类定义的接口进行访问,

可以在不影响客户程序员使用的情况下,修改具体的内部实现

public ——任何人都可以访问

private ——只有类的创建者可以访问

protected ——只有继承类可以访问

package ——缺省的访问权限

同属某个package的类可以访问其他类的缺省访问权限的成员

在package外,缺省访问权限的成员被当做 private 成员

+ -
复用实现

直接用某个类创建它的对象

把类的对象放到一个新的类中——创建一个成员对象

合成 composition —— 用多个不同类型的已有的类组合成新的类

聚合 aggregation —— 动态合成

通常将“合成”成为 has-a 关系 ,例如:轿车有引擎

在创建新类时,应当优先考虑使用“合成”

+ -
继承:复用接口

基类,超类,父类

派生类,继承类,子类

基类的变化,会对派生类产生影响

基类保存的是所有继承自它的类的共有特征和行为

所有可以传给基类的消息也都可以传给其派生类

可以通过一个类可以接收什么消息来判断这是一个什么类

派生类与基类是属于同一类型的——类的相等性

extends

override——在派生类中重新定义基类的方法

完全替换(pure substitution)

is-a 关系

is-like-a 关系

+ -
多态

泛型

后绑定

upcasting

+ -
abstract 类

编译器会禁止任何人创建abstract 类的对象

abstract 方法

abstract 方法只存在于 abstract 类中

abstract 方法表示由该类派生的所有类都有这个方法,

但这个方法的实现不在这里

如果某个类继承自abstract 类,那么要么把abstract

方法实现,要么也是一个abstract 类

+ -
interface 关键字

不允许实现任何方法,将接口与实现彻底的分离

可以继承多个接口,但是不能继承多个常规类或抽象类

+ -
对象的创建

在堆中创建——C++ 的做法

在栈中创建——java 的做法

new 关键字

垃圾回收器

+ -
容器(container)

迭代器

单根继承体系

上传/下传/参数化类型

异常处理

+ -
并发

线程

锁定资源

persistence

+ -
java与internet

web

客户端编程

插件

脚本语言

服务器端编程

servlet

JSP

+ -
java为什么会成功

系统能更易于表述和理解

最大程度上利用类库

异常处理

适于编写大型系统

java 还是 C++ ?

fold_document();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: