diff --git a/notes/pics/uml-aggregation.png b/notes/pics/uml-aggregation.png new file mode 100644 index 00000000..a35c22c8 Binary files /dev/null and b/notes/pics/uml-aggregation.png differ diff --git a/notes/pics/uml-association.png b/notes/pics/uml-association.png new file mode 100644 index 00000000..0fc90446 Binary files /dev/null and b/notes/pics/uml-association.png differ diff --git a/notes/pics/uml-composition.png b/notes/pics/uml-composition.png new file mode 100644 index 00000000..3f1802a5 Binary files /dev/null and b/notes/pics/uml-composition.png differ diff --git a/notes/pics/uml-dependency.png b/notes/pics/uml-dependency.png new file mode 100644 index 00000000..cfa03dd7 Binary files /dev/null and b/notes/pics/uml-dependency.png differ diff --git a/notes/pics/uml-generalization.png b/notes/pics/uml-generalization.png new file mode 100644 index 00000000..3aef7909 Binary files /dev/null and b/notes/pics/uml-generalization.png differ diff --git a/notes/pics/uml-realization.png b/notes/pics/uml-realization.png new file mode 100644 index 00000000..d819b03f Binary files /dev/null and b/notes/pics/uml-realization.png differ diff --git a/notes/面向对象思想.md b/notes/面向对象思想.md index ecd8406b..9494ea87 100644 --- a/notes/面向对象思想.md +++ b/notes/面向对象思想.md @@ -137,25 +137,25 @@ Percussion is playing... ## 二、类图 -以下类图使用 [PlantUML](https://www.planttext.com/) 绘制,更多语法及使用请参考:http://plantuml.com/ 。 +每张类图后附有对应的 [PlantUML](https://www.planttext.com/) 代码,更多语法及使用请参考:http://plantuml.com/ 。 ### 泛化关系 (Generalization) 用来描述继承关系,在 Java 中使用 extends 关键字。 -

+

```text @startuml title Generalization -class Vihical +class Vehicle class Car -class Trunck +class Truck -Vihical <|-- Car -Vihical <|-- Trunck +Vehicle <|-- Car +Vehicle <|-- Truck @enduml ``` @@ -164,7 +164,7 @@ Vihical <|-- Trunck 用来实现一个接口,在 Java 中使用 implements 关键字。 -

+

```text @startuml @@ -185,7 +185,7 @@ MoveBehavior <|.. Run 表示整体由部分组成,但是整体和部分不是强依赖的,整体不存在了部分还是会存在。 -

+

```text @startuml @@ -208,7 +208,7 @@ Computer o-- Screen 和聚合不同,组合中整体和部分是强依赖的,整体不存在了部分也不存在了。比如公司和部门,公司没了部门就不存在了。但是公司和员工就属于聚合关系了,因为公司没了员工还在。 -

+

```text @startuml @@ -229,7 +229,7 @@ Company *-- DepartmentB 表示不同类对象之间有关联,这是一种静态关系,与运行过程的状态无关,在最开始就可以确定。因此也可以用 1 对 1、多对 1、多对多这种关联关系来表示。比如学生和学校就是一种关联关系,一个学校可以有很多学生,但是一个学生只属于一个学校,因此这是一种多对一的关系,在运行开始之前就可以确定。 -

+

```text @startuml @@ -239,7 +239,7 @@ title Association class School class Student -School "1" - "n" Student +School "1" - "*" Student @enduml ``` @@ -252,14 +252,14 @@ School "1" - "n" Student - A 类是 B 类方法的参数; - A 类向 B 类发送消息,从而影响 B 类发生变化。 -

+

```text @startuml title Dependency -class Vihicle { +class Vehicle { move(MoveBehavior) } @@ -269,9 +269,9 @@ interface MoveBehavior { note "MoveBehavior.move()" as N -Vihicle ..> MoveBehavior +Vehicle ..> MoveBehavior -Vihicle .. N +Vehicle .. N @enduml ``` @@ -352,7 +352,7 @@ Vihicle .. N #### 3. 共同封闭原则 -一起修改的类,应该组合在一起(同一个包里)。如果必须修改应用程序里的代码,我们希望所有的修改都发生在一个包里(修改关闭),而不是遍布在很多包里。 +一起修改的类,应该组合在一起(同一个包里)。如果必须修改应用程序里的代码,希望所有的修改都发生在一个包里(修改关闭),而不是遍布在很多包里。 #### 4. 稳定抽象原则