I just reworked a new domain class from a presenter class, but I cannot figure out where to create it.
This is part of a larger ongoing refactoring effort with a poorly preserved obsolete project.
Currently, Presenter is created by the OnLoad view and the view is passed as a parameter in the constructor. All public methods in the presenter are without parameters and return to void. They interact with the view using the publicly available properties of the view.
The view, which is essentially a modest form, is completely dependent on the leader for everything.
This is a typical passive pattern, and I would like to continue to stick to it. This brings me to my dilemma. I need to instantiate my new domain object for use by the presenter.
- If I pass it through the constructor, then the view should create it and get an unnecessary dependency.
- If I create it anywhere in the presenter, I cannot replace it with a mock object in my unit tests.
- If I make this a public property of the host, then I introduce the dependence of the order of creation on the methods of the presenter, where it is used, and I still have not decided which external class receives responsibility for its creation.
I currently do not use any dependency injection frameworks. Although I'm interested in using one in the future, the source code is still very fragile to incorporate a third-party structure into the mix.
I am open to any suggestions.
source share