Closed teamdisc closed 4 years ago
@teamdisc For me, I quite agree with this approach because it reduces the unwrap expression inside the Presenter. I also want to move the initial setting (* and **) into the Presenter initializer. What do you think about it?
final class SomeModule {
let view: SomeViewController
let presenter: SomePresenter
let router: SomeRouter
let interactor: SomeInteractor
...
var input: SomeInput {
return presenter
}
init() {
view = SomeViewController()
router =SomeRouter()
interactor = SomeInteractor()
presenter = SomePresenter(interactor: interactor, router: router)
view.output = presenter
presenter.view = view
// What do you think about moving * and ** into presenter?
// interactor.output = presenter // *
// router.view = view // **
}
}
final class SomePresenter {
let interactor: SomeInteractor
let router: SomeRouter
weak var view: SomeViewInput?
weak var output: SomeOutput?
init(interactor: SomeInteractor, router: SomeRouter) {
self.interactor = interactor
interactor.output = self
self.router = router
router.view = view // *** Related to issue 19th
}
}
The main reason is that I want to keep the setting in one place, it's easier to trackback where we did set delegations between Presenter - Interactor, Presenter - Router and Router - View...
The last thing I'd like to bring up is what we discussed 2 weeks ago.
So I think we might not need
Interactor
andRouter
to be optional inPresenter
. This is what we currently haveIt's not really a big deal here tho, but the problem here is that we need to
guard let
our interactor when using it. In most cases, it would be fine as we could just make it likeinteractor?.doSome()
here. But sometimes, we might need to use our interactor to validate some condition likeWhile it might be a bit more straightforward if we could do something like
The way I see it is that, since
Interactor
andRouter
are gonna be strongly captured byPresenter
anyway. Maybe we could just inject them in the first placeThe downside for this one, IMO, is that we might have a bigger
init
function that we usually have. But I think, in most cases,Presenter
doesn't really have many dependencies anyway as they are likely to be inInteractor
layer.Let me know what you guys think about it 🤔