Skip to content
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

head first 设计模式-0x04 #16

Open
ichengzi opened this issue May 24, 2020 · 0 comments
Open

head first 设计模式-0x04 #16

ichengzi opened this issue May 24, 2020 · 0 comments

Comments

@ichengzi
Copy link
Owner

ichengzi commented May 24, 2020

工厂模式

  1. 简单工厂方法

一般静态方法, 只有一种实现,new对象

  1. 工厂方法

抽象类里的一个抽象方法,具体的实现类中来实现, new对象

  1. 抽象工厂

定义一个契约接口,用于生产一系列产品。 抽象类中再实现再传入这个接口的实现。 类似策略模式的实现

concrete: 具体物
concreteCreator: 具体实现类的创建

原则

  1. 代码里, 要减少得实具体实现类的依赖。
    要依赖抽象, 不要依赖具体类

1.变量不可以持有具体类的引用
2.不要让类派生自具体类
3.不要覆盖基类中已实现的方法

NOTE: 正如许多原则一样, 应该尽量达到这个原则,而不是随时都要遵守这个原则。设计时, 多思考, 何时有足够的理由违反这样的原则。

@ichengzi ichengzi changed the title head firset -设计模式0x04 head first 设计模式-0x04 May 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant