|
BestPractices
Best practices
The PlaceManager is the best way to decouple your codeGuit allow you to store complex data into your places. But complexity is not always the solution. i.e: Direct reference (Bad): ProductListPresenter implements Place<Void> ProductListPresenter @Injects ProductViewerPresenter // Call productViewerPresenter.show(productId); Decoupled throw the PlaceManager (Better): ProductListPresenter implements Place<Void> ProductViewerPresenter implements Place<Integer> // the product id // Call placeManager.go(ProductViewerPresenter.class, productId); Hide your presenters behind an apiInstead of injecting a presenter into another, inject an interface. i.e Injecting presenters (Bad): class MyComplexPresenter .... {
public void doSomething() {
...
}
}
class MyAnotherPresenter ... {
@Inject
public MyAnotherPresenter(MyComplexPresenter myComplexPresenter) {
myComplexPresenter.doSomething();
}
}Injecting api (Better): interface MyComplexPresenter {
void doSomething();
}
class MyComplexPresenterImpl .... implements MyComplexPresenter {
@Override
public void doSomething() {
...
}
}
class MyAnotherPresenter ... {
@Inject
public MyAnotherPresenter(MyComplexPresenter myComplexPresenter) {
myComplexPresenter.doSomething();
}
}
| |