I don't understand the additional decoupling the abstract factory design pattern would add in this situation :
Let's say I have :
-
a mapper which is generic :
public interface Mapper<A,B> { [mapper methods]}
-
a concrete class that implements this mapper interface:
JsonMapper implements Mapper<Json,ModelObject>{ [mapper methods implemented..] }
Now I want to use a mapper in a third object, a repository for instance :
OnlineRepo {
Mapper<Json, ModelObject> mMapper;
OnlineRepo(Mapper<Json, ModelObject> jsonToModelMapper ){
mMapper = jsonToModelObject;
}
// other repo methods using mMapper, get, upsert etc etc...
}
And finally my main code may assembly the whole (instanciating concrete classes/implementations).
main{
JsonMapper mapper = new JsonMapper(); // reference to concrete JsonMapper
OnlineRepo repo = new OnlineRepo(mapper); // inject concrete JsonMapper
}
How would the factory design pattern help me decouple these objects ?
-
The
OnlineRepository
does not directly reference the concreteJsonMapper
it references only the abstractMapper<Json, ModelObject>
. Isn't it ? -
How would an abstract factory design pattern would help me decouple this code even more.
-
It seems like I will always need to reference an implementation in my main program (if not an implementation of JsonMapper, an implementation of JsonMapperFactory ?).
To better illustrate I do not see the advantage of this :
over this :
I hope my question is clear, if not, do not hesitate to state it to help me redact it better.
Thanks in advance for your help. Best, Antonin
Aucun commentaire:
Enregistrer un commentaire