vendredi 19 janvier 2018

Design pattern for creating object graph

I have a situation where I want create a hierarchy of instances (belonging to separate classes) in my android application where each object is standalone ie., they fulfill their own responsibilities. So I dont need any other class to hold references to these objects and call any methods on this class. However I need any entry point ie., these classes should be instantiated when a controller class gets instantiated.

I use dagger to for object instantiation. So if MyClassA and MyClassB are two standalone classes which should get instantiated when MyController gets instantiated, its constructor will look like this

@Inject
public MyController(MyClassA a, MyClassB b) {
  ...
}

But MyController has no reason to hold onto these references. So the code looks confusing as it appears that MyController is unnecessarily injecting these two parameters even if it doesn't use them.

Is there a suggested design pattern in this scenario which avoids this confusion ?

Aucun commentaire:

Enregistrer un commentaire