katsusan / gowiki

0 stars 0 forks source link

Object-Oriented, From Jonathan Rees #6

Open katsusan opened 4 years ago

katsusan commented 4 years ago

这篇文章里有关于OO的一些定义。

  1. Encapsulation - the ability to syntactically hide the implementation of a type. E.g. in C or Pascal you always know whether something is a struct or an array, but in CLU and Java you can hide the difference. 封装 - 语法上隐藏类型的细节。比如C或Pascal中你很清楚某个东西是结构体还是数组,但在CLU和Java中这个可以被隐藏掉。

  2. Protection - the inability of the client of a type to detect its implementation. This guarantees that a behavior-preserving change to an implementation will not break its clients, and also makes sure that things like passwords don't leak out. 保护 - 让类型的使用对象无法得知其具体实现。这保证了对实现的保留性修改不会影响到使用对象,也能够确保密码之类的成员信息不泄露出去。

  3. Ad hoc polymorphism - functions and data structures with parameters that can take on values of many different types. Ad hoc多态 - 函数与数据结构的参数可以接受很多不同类型值。注意这里与下面的参数多态不同,并非类型无关,它是与类型绑定的,例如golang里的interface,在编译期就推导出实现。

  4. Parametric polymorphism - functions and data structures that parameterize over arbitrary values (e.g. list of anything). ML and Lisp both have this. Java doesn't quite because of its non-Object types. Parametric参数多态 - 函数和数据结构可以用任意值(比如任意list)来参数化。ML和Lisp都实现了这个,Java由于其non-Object的类型因此并没有完全实现它。

  5. Everything is an object - all values are objects. True in Smalltalk (?) but not in Java (because of int and friends). 万物皆对象 - 所有的值都是对象。Smalltalk中完全满足但Java里由于int和friends 的存在则并非完全这样。

  6. All you can do is send a message (AYCDISAM) = Actors model - there is no direct manipulation of objects, only communication with (or invocation of) them. The presence of fields in Java violates this. 你能做的唯一事情就是发消息 = Actors模型 - 除了与之通信,无法直接操纵对象。Java中字段的存在违反了这一约定。

  7. Specification inheritance = subtyping - there are distinct types known to the language with the property that a value of one type is as good as a value of another for the purposes of type correctness. (E.g. Java interface inheritance.) 规范继承= 子类型 - 在保证类型正确的基础上有不同的类型可以满足,比如Java的接口继承。

  8. Implementation inheritance/reuse - having written one pile of code, a similar pile (e.g. a superset) can be generated in a controlled manner, i.e. the code doesn't have to be copied and edited. A limited and peculiar kind of abstraction. (E.g. Java class inheritance.) 实现继承/重用 - 可以用指定的方式来在一堆已有的代码上生成类似的代码,比如Java的类继承。

  9. Sum-of-product-of-function pattern - objects are (in effect) restricted to be functions that take as first argument a distinguished method key argument that is drawn from a finite set of simple names. 函数积之和模式?- 实际上对象被限定为将第一个参数作为特别的方法以区分方法关键参数的函数。