Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision |
rfc:customfactories [2009/11/18 15:20] – created robertlemke | rfc:customfactories [2017/09/22 13:28] (current) – external edit 127.0.0.1 |
---|
| |
Now "Foo" does not depend on any specific implementation, neither on an actual ObjectFactory nor on a specific Email implementation. But this comes with a price: At most places where the "new" operator would usually be used to instantiate classes, the ObjectFactory or some other kind of factory needs to be called. If the mechanism of Dependency Injection is consequently used, this results in a lot of additional typing and many classes will need the ObjectFactory getting injected by the surrounding framework. | Now "Foo" does not depend on any specific implementation, neither on an actual ObjectFactory nor on a specific Email implementation. But this comes with a price: At most places where the "new" operator would usually be used to instantiate classes, the ObjectFactory or some other kind of factory needs to be called. If the mechanism of Dependency Injection is consequently used, this results in a lot of additional typing and many classes will need the ObjectFactory getting injected by the surrounding framework. |
| |
===== Proposal ===== | ===== Proposal ===== |
| |
class Foo { | class Foo { |
public function bar() { | public function bar() { |
| // Instantiate by class name: |
| $email = new Email(); |
| // or even instantiate by interface name (the factory needs to find the right implementation): |
$email = new EmailInterface(); | $email = new EmailInterface(); |
} | } |
[2] Robert Lemke, "FLOW3 Object Framework" | [2] Robert Lemke, "FLOW3 Object Framework" |
http://flow3.typo3.org/documentation/manuals/flow3/flow3.objectframework/ | http://flow3.typo3.org/documentation/manuals/flow3/flow3.objectframework/ |
| |