gpt4 book ai didi

design-patterns - 抽象工厂与工厂方法 : Composition vs Inheritance?

转载 作者:行者123 更新时间:2023-12-02 01:05:49 25 4
gpt4 key购买 nike

<分区>

我看了很多关于Abstract Factory和Factory method的区别的帖子,但是有一个问题我无法理解。

One difference between the two is that with the Abstract Factorypattern, a class delegates the responsibility of object instantiationto another object via composition whereas the Factory Method patternuses inheritance and relies on a subclass to handle the desired objectinstantiation

也许我知道为什么抽象工厂模式使用组合和委托(delegate)来创建对象,但我无法理解为什么工厂方法模式使用继承来创建具体的类对象。


这个问题不是关于什么是抽象工厂或什么是工厂方法,因此没有答案 here

这是关于为什么当客户端也可以直接调用工厂方法时,工厂方法似乎使用继承。请取消将其标记为重复。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com