What are disadvantages of Abstract factory design pattern?

回眸只為那壹抹淺笑 提交于 2019-12-10 05:24:27

问题


As usual to build the project with different design patterns, architects always prefer the advantageous view of that particular design pattern. But sometimes it need to understand what should be the violation area and disadvantages in terms of future extension of project. I am using Abstract factory design pattern now a days. I understood it but unable to figure out its disadvantages,its limitations, where it will get fail. can somebody please explain me this another view of Abstract Factory design pattern?


回答1:


First, with any design pattern you are adding more layers of abstraction and complexity, so only apply the pattern when the pain of not having it is apparent. This is a similar idea to Bob Martin's "Take the first bullet" and Nathan Marz' "Suffering-Oriented Programming."

With Abstract Factory in particular, the decision about which factory to use is made at runtime. Typically, this is done in some code dedicated to providing the right factory by conditional branching based on some key piece of information. This means as more factories are created, this central decision point must be modified. That's annoying.

Finally, if there are any changes to any underlying detail of one factory, the interface might need to be modified for all the factories. This breaks clients. So as usual, take great care with the choice of interfaces.



来源:https://stackoverflow.com/questions/19508928/what-are-disadvantages-of-abstract-factory-design-pattern

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!