What is a Factory Design Pattern in PHP?

2019-01-05 08:42发布

This confuses me, in the most simplest terms what does it do? Pretend you are explaining to your mother or someone almost please.

标签: php factories
9条回答
我欲成王,谁敢阻挡
2楼-- · 2019-01-05 09:21

This answer is in relation to other post in which Daniel White said to use factory for creating MySQL connection using factory pattern.

For MySQL connection I would rather use singleton pattern as you want to use same connection for accessing the database not create another one.

查看更多
对你真心纯属浪费
3楼-- · 2019-01-05 09:22

Factory Design Pattern (Factory Pattern) is for loose coupling. Like the meaning of factory, data to a factory (produce data) to final user. By this way, the factory break the tight coupling between source of data and process of data.

查看更多
放我归山
4楼-- · 2019-01-05 09:25

A factory just generates an object or objects.

You may have a factory that builds a MySQL connection.

http://en.wikipedia.org/wiki/Factory_method_pattern

查看更多
登录 后发表回答