Symfony 2 中的表单:'inherit_data' 或 class 继承?

Forms in Symfony 2: 'inherit_data' or class inheritance?

我需要使用继承在 Symfony 2.8 中创建一堆表单。我已经看到使用了两种方法:

  1. 使用 'regular' class 继承,如所述 in the first answer here
  2. 使用 inherit_data.

两者有什么区别?为什么我会选择一个而不是另一个?

此外,我能否将我的 'base'-form 类型设为抽象类型 class,以防止它被单独使用?这有什么缺点吗?

很快,所有需要的信息都已经在您发布的链接中公开了。

表单继承是关于真正的 OOP class 继承。 inherit_data 用于组合方法,因此您可以在表单中使用它,这些表单在逻辑上并没有真正从基础 class.

继承。

这实现了组合优于继承的方法 https://en.m.wikipedia.org/wiki/Composition_over_inheritance