在我的设计中,一开始,我是在设计一个工厂模式。但是有人建议更好地使用桥接模式。
这是我的场景:How to improve my abstract factory pattern?
我只想知道哪种模式最适合这种情况。我很困惑!
我的场景总结如下:
Imagine a black box, this black box receives a object called
Configuration
and it output is aProblem
objectThis black box at the beginning I was calling a factory, but later I need to use generics to be more specific in my abstract class and so, one person told better use the bridge.
Also, in my factory, needs to receive the input value in the constructor, and also can modify the instance.. so this part is the cruxial.
我不太了解那个模式,所以我只想使用这个简短的场景,我该怎么办?
最佳答案
你不需要一座桥。它曾经有一个接口(interface),可以使用多个实现。这允许在用户不知情的情况下切换实现。 您想同时使用问题工厂和配置工厂。
如果您想在用户不知情的情况下在使用问题和配置部分之间切换,那么您可以使用桥接器。
请记住,您可以根据需要同时使用任意多个模式,而且在这种情况下,您不会被迫在其中进行选择。使用您认为最有效的方法。
关于c# - 桥接模式还是工厂模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9931755/