I am writing some code to parse some files (which I call "assets"), and I'm planning to structure this as three classes: AssetParser
, NamespacesParser
, and TransfomersParser
. AssetParser
will use objects of the other two classes to parse some parts of the assets.
I want to write this as three classes rather than one big class to split functionality into manageable fragments (that is I use something like structured programming, where methods of AssetParser call methods of the other two classes)
My question: Should I use dependency injection to create objects of NamespacesParser
and TransformersParser
classes?
The parts of the parser are tightly coupled to the parsers. In my opinion, it is highly unlikely that AssetParser
would use other subparsers in place of NamespacesParser
and TransformersParser
. So it looks like that dependency injection is not necessary here. (I can just use new
to create objects of NamespacesParser
and TransformersParser
.)
One reason to use dependency injection is that it allows easily make NamespacesParser
and TransformersParser
singletons (if I will want to use singletons). Are there other reasons?
NamespacesParser
(in order to easily switch between factory provider and singleton provider), but call the provider directly fromAssetParser
instead of dependency injection (because I find no reason to use dependency injection)?AssetParser
call methods of the other two classes). I am going to write all three classes now. Dear bdsl: I do not quite understand your questions. Is this comment a good answer?