《The Object-Oriented Thought Process》读书笔记2

本文探讨了面向对象设计的核心原则,包括识别公共接口、构造稳健的构造函数、内存管理、错误处理、类间合作等关键议题,并强调了抽象、可重用性和可维护性的重要性。

5 Class Design Guidelines

Identifying the public interfaces

The entire purpose of building a class isto provide something useful and concise.

The minimum public interface

necessitate

[英] [niˈsesiteit][美] [nəˈsɛsɪˌtet]

vt. 使…成为必要,需要;强迫,迫使

Gilbert and McCarty state that the primedirective of encapsulation is that “all fields shall be private.”

Designing Robust Constructors (and Perhaps destructors)

A constructor should put an object into aninitial, safe state.

Destructors include proper clean-upfunctions.

Memory Leaks

Designing Error Handling into a Class

Documenting a Class and Using Comments

Too Much Documentation

Building Objects with the Intent to Cooperate

A class will service other classes; it willrequest the services of other classes, or both.

Designing with Reuse in Mind

All the possible scenarios

scenarios

中频词,你记住了吗?

[sɪ'nɑ:ri:əʊz][sɪ'nɑrioʊz]

n. []情节;剧本;事态;脚本

Designing with Extensibility in Mind

Thus, having Employee inherit from Person might be the best strategy; in

this case, the Person class is said to be extensible.

For example, youwould not want to code functionality into an Employee

class that isspecific to supervisory functions. If you did, and then a class that does notrequire

supervisory functionalityinherited from Employee, you would have a problem.

Making Names Descriptive

Good Naming

Abstracting Out Nonportable Code

If you aredesigning a system that must use nonportable code (that is, the code will only

run on a specific hardwareplatform), you should abstract this code out of the class.

Providing a Way to Copy and Compare Objects

Chapter3

Keeping the Scope as Small as Possible

Scope and Global Data

In fact, there really is no global data in OO development. Staticattributes and methods

are shared among objects of the same class; however, they are notavailable to objects

not of theclass.

A Class Should Be Responsible for Itself

Shape.print();//Shape is actually a circle

Shape.print();//Shape is actually a square

The important thing to understand here isthat the call is identical; the context of the shap dictates how the systemreacts.

A shape knows how to print itself.

Designing with Maintainability(可维护性) in Mind

One of the best ways to promotemaintainability is to reduce interdependent code.

Classes that are highly dependent on oneanother are considered highly coupled.

To promote a high level of maintainability,keep the coupling level of your classes as low as possible.

Using Iteration(迭代)

Testing the Interface

Using stubs(插桩),

albeit

英 [ˌɔ:lˈbi:ɪt] 美 [ɔlˈbiɪt, æl-]

conj. 虽然;即使

Keeping the Stubs Around

Using Object Persistence

对象保存

n Flat file system

n Relationaldatabase

n OO database

Serializing and Marshaling Objects

serialization and deserialization

对象序列化:

1.在做对象数据传输时,由于对象中的数据很庞大。在传输之前,需要将对象打散成字节序列,以利于传输。这个过程叫序列化过程。

 

2.达到目的地后,又需要将字节序列还原成对象,这叫反序列化过程。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值