Consider the following architecture designed for logging operations Add
/Update
that are being done on an instance of Entity
.
LogFactory
is an Abstract Factory
and receives two factories for Add
and Update
via constructor using DI
. Both concrete factories AddLogFactory
and UpdateLogFactory
implement ILogFactory
in order to produce an ILog
. They both need an Entity
to collect log-able data. Well, I hope everything is clear and you admit Abstract Factory
pattern is the right solution so far.
Problem:
UpdateLogFactory
is an exception because it needs additional data: ModifiedProperties
to create a before/after string (meanwhile its siblings i.e. other types implementing ILogFactory
don't need this kind of data; an Entity
suffices them). In order to not break the ILogFactory
, I decided to give ModifiedProperties
to UpdateLogFactory
via its constructor. It solves my problem but I feel I'm cheating somehow; I'm pretending UpdateLogFactory
is similar to others while it is actually not.
If someone wants to replace ILogFactory
with another concrete type how does he know it needs ModifiedProperties
?
Aucun commentaire:
Enregistrer un commentaire