mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-02-22 20:22:18 +08:00
oop 部分修正
This commit is contained in:
parent
feea3b4763
commit
b994a14a56
@ -98,7 +98,7 @@
|
||||
- [共享状态](ch16-03-shared-state.md)
|
||||
- [可扩展的并发:`Sync` 与 `Send`](ch16-04-extensible-concurrency-sync-and-send.md)
|
||||
|
||||
- [Rust 的面向对象编程特征](ch17-00-oop.md)
|
||||
- [Rust 的面向对象编程特性](ch17-00-oop.md)
|
||||
- [面向对象语言的特点](ch17-01-what-is-oo.md)
|
||||
- [为使用不同类型的值而设计的 trait 对象](ch17-02-trait-objects.md)
|
||||
- [面向对象设计模式的实现](ch17-03-oo-design-patterns.md)
|
||||
|
@ -1,7 +1,12 @@
|
||||
# Rust 是一个面向对象的编程语言吗?
|
||||
# Rust 的面向对象特性
|
||||
|
||||
> [ch17-00-oop.md](https://github.com/rust-lang/book/blob/master/second-edition/src/ch17-00-oop.md)
|
||||
> [ch17-00-oop.md][ch17-00]
|
||||
> <br>
|
||||
> commit 28d0efb644d18e8d104c2e813c8cdce50d040d3d
|
||||
> commit 07b0ca8c829af09d60ab4eb9e69584b6f4a96f60
|
||||
|
||||
面向对象编程(Object-Oriented Programming)是一种起源于 20 世纪 60 年代的 Simula 编程语言的模式化编程方式,然后在 90 年代随着 C++ 语言开始流行。关于 OOP 是什么有很多相互矛盾的定义,在一些定义下,Rust 是面向对象的;在其他定义下,Rust 不是。在本章节中,我们会探索一些被普遍认为是面向对象的特性和这些特性是如何体现在 Rust 语言习惯中的。接着会展示如何在 Rust 中实现面向对象设计模式,并讨论这么做与利用 Rust 自身的一些优势实现的方案相比有什么取舍。
|
||||
[ch17-00]: https://github.com/rust-lang/book/blob/master/second-edition/src/ch17-00-oop.md
|
||||
[commit]: https://github.com/rust-lang/book/commit/07b0ca8c829af09d60ab4eb9e69584b6f4a96f60
|
||||
|
||||
面向对象编程(Object-Oriented Programming,OOP)
|
||||
|
||||
面向对象编程(Object-Oriented Programming,OOP)是一种起源于 20 世纪 60 年代的 Simula 编程语言的模式化编程方式,然后在 90 年代随着 C++ 语言开始流行。关于 OOP 是什么有很多相互矛盾的定义,在一些定义下,Rust 是面向对象的;在其他定义下,Rust 不是。在本章节中,我们会探索一些被普遍认为是面向对象的特性和这些特性是如何体现在 Rust 语言习惯中的。接着会展示如何在 Rust 中实现面向对象设计模式,并讨论这么做与利用 Rust 自身的一些优势实现的方案相比有什么取舍。
|
||||
|
@ -18,10 +18,6 @@ had this to say about it https://www.martinfowler.com/bliki/GangOfFour.html:
|
||||
|
||||
`Design Patterns: Elements of Reusable Object-Oriented Software` 这本书被俗称为 `The Gang of Four book`,是面向对象编程模式的目录。它这样定义面向对象编程:
|
||||
|
||||
> Object-oriented programs are made up of objects. An *object* packages both
|
||||
> data and the procedures that operate on that data. The procedures are
|
||||
> typically called *methods* or *operations*.
|
||||
>
|
||||
> 面向对象的程序是由对象组成的。一个 **对象** 包含数据和操作这些数据的过程。这些过程通常被称为 **方法** 或 **操作**。
|
||||
|
||||
在这个定义下,Rust 是面向对象的:结构体和枚举包含数据而 impl 块提供了在结构体和枚举之上的方法。虽然带有方法的结构体和枚举并不被 **称为** 对象,但是他们提供了与对象相同的功能,参考 Gang of Four 中对象的定义。
|
||||
|
Loading…
Reference in New Issue
Block a user