When to use Factory method pattern?

后端 未结 10 1459
南旧
南旧 2020-12-12 14:56

When to use Factory method pattern?

Please provide me some specific idea when to use it in project? and how it is a better way over new keyword?

10条回答
  •  眼角桃花
    2020-12-12 15:51

    I think its when you want your application to be loosely coupled and extensible in future without coding changes.

    I have written a post on blog as to why i choose the factory pattern in my project and may be it can give you more insight. The example is in PHP but i think its applicable in general to all languages.

    http://www.mixedwaves.com/2009/02/implementing-factory-design-pattern/

提交回复
热议问题