Skip to content

Fix typos #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions 2.面向对象设计原则.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
###### 1. 开放封闭原则
一个软件实体如类、模块和函数应该对扩展开放,对修改关闭。即软件实体应该在不修改原代码的情况下进行修改。
###### 2. 里氏替换原则
所有引用父类的地方必须能透明地使用其子类地方必须能透明地使用其子类的对象,一个简单的例子加强理解
所有引用父类的地方必须能透明地使用其子类的对象,一个简单的例子加强理解
```py
class User(object):
def print_name(self):
Expand All @@ -24,7 +24,7 @@ def print_name(u):
u.print_name()
```
###### 3. 依赖倒置原则
高层模块不应该依赖底层模块,二者都应该依赖抽象。抽象不应该依赖细节,细节应该应该依赖抽象。**`要针对接口编程,而不是针对实现变成`**。通过例子加强理解:
高层模块不应该依赖底层模块,二者都应该依赖抽象。抽象不应该依赖细节,细节应该应该依赖抽象。**`要针对接口编程,而不是针对实现编程`**。通过例子加强理解:
```py
from abc import ABCMeta, abstractmethod

Expand All @@ -51,7 +51,7 @@ a.pay(100)
w.pay(100)
```
###### 4. 接口隔离原则
使用多个专门的接口,而不使用单一的总结口,高层的代码不应该依赖那些它不需要的接口。通过例子加强理解:
使用多个专门的接口,而不使用单一的总接口,高层的代码不应该依赖那些它不需要的接口。通过例子加强理解:
```py
from abc import ABCMeta, abstractmethod

Expand Down
12 changes: 6 additions & 6 deletions 3.创建型模式.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class WechatPay(Payment):

# 工厂类角色
class PaymentFactory:
def ctreate_payment(self, method):
def create_payment(self, method):
if method == 'Alipay':
return Alipay()
elif method == 'WechatPay':
Expand All @@ -41,7 +41,7 @@ class PaymentFactory:

# 客户端调用。不直接向客户端暴露对象创建的实现细节,而是通过一个工厂类来负责创建产品类的实例
pf = PaymentFactory()
p = pf.ctreate_payment('HuabeiPay')
p = pf.create_payment('HuabeiPay')
p.pay(100)
```
###### 2. 工厂方法模式
Expand Down Expand Up @@ -84,7 +84,7 @@ class AlipayFactory(PaymentFactory):

class WechatPayFactory(PaymentFactory):
def create_payment(self):
return Alipay()
return WechatPay()

class HuabeiFactory(PaymentFactory):
def create_payment(self):
Expand Down Expand Up @@ -134,7 +134,7 @@ class AlipayFactory(PaymentFactory):
# 工厂类
class WechatPayPayFactory(PaymentFactory):
def create_payment(self):
return Alipay()
return WechatPay()

# 工厂类
class HuabeiPayFactory(PaymentFactory):
Expand Down Expand Up @@ -189,7 +189,7 @@ class SnapDragonCPU(PhoneCPU):

class HuaweiCPU(PhoneCPU):
def show_cpu(self):
print('化为CPU')
print('华为CPU')

class AppleCPU(PhoneCPU):
def show_cpu(self):
Expand Down Expand Up @@ -262,7 +262,7 @@ p.show_info()
"""
手机信息:
普通手机小手机壳
化为CPU
华为CPU
IOS系统
"""
```
Expand Down