抽象工厂设计模式的缺点是什么? [英] What are disadvantages of Abstract factory design pattern?

查看:131
本文介绍了抽象工厂设计模式的缺点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

像往常一样,用不同的设计模式构建项目,建筑师总是喜欢那种特定设计模式的有利视图。但有时需要了解什么是违法区域和未来扩展项目的缺点。我现在使用抽象工厂设计模式一天。我理解它,但无法找出它的缺点,它的局限性,它会失败。可以有人请解释一下抽象工厂设计模式的另一种观点?

as usual to build the project with different design patterns architect 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?

推荐答案

首先,的抽象和复杂性,所以只有当没有它的疼痛显而易见的应用模式。这与Bob Martin的Take the first bullet和Nathan Marz的观点相似: Suffering-面向对象编程

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.

这篇关于抽象工厂设计模式的缺点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆