06.
Constructor en Symfony y con una Fábrica
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
4 Comments
Sorry I had a little trouble with understanding why
CharacterBuilderFactoryis a service andCharacterBuilderis not.So in my understanding a typical class is not a service and cannot autowire until it is autowired by another class (in this example
GameApplication)?Hey Kacper,
The intention of the
CharacterBuilderFactoryis to allow us to instantiate as manyCharacterBuilderobjects as we want. In this case, we can't reuse the same instance of aCharacterBuilderbecause after you use it to create aCharacterobject it holds state (health, damage, armor, etc.), so, instead of clearing the state we just instantiate another builder object. It was done this way for convenience and for quickly talking about the factory pattern.Cheers!
Well, even though
CharacterBuilderis not a service, after we addLoggerInterfaceto its constructor, it will beautowiredby a container, as well ass injected by the factory. Shouldn't namespace of the builder be excluded from auto-wiring in the configuration, to actually inject it only by the factory?Hey Sargath,
Good question. At this exact moment, it makes sense to exclude that
CharacterBuilderfrom the auto-wiring configuration. Though, further in the course, we will rewrite it into a Symfony service. So, for simplicity, we do not focus on this too much right now, i.e. because eventually, we want it to be a real service in our Symfony app.But if you want to leave the code as it is in this specific chapter - yeah, you can ignore it which makes more sense :) Though, while you're not using that
CharacterBuilderas a service anyway - it's still no that much important ;)Anyway, a good catch ;)
Cheers!
"Houston: no signs of life"
Start the conversation!