M
marlow.andrew
Please excuse this being off-topic. I admit this is not special to
java but a question about programming generally. [if there's a better
newsgroup please let me know which one!]
I am not sure why some people advocate using the factory design
pattern to create instances of objects where the constructor could be
used just as easily (IMHO). I am aware of the Abstract Factory design
pattern (AFDP) in the GoF and I do agree that AFDP has its uses. But
what is being advocated (not by me) in this case is a non-abstract
factory.
Recently I have been working in an agile envirornment and on two
separate occasions my pair partner (a different person each time)
stopped me from creating an object via its constructor and got me to
use the non-abstract factory design pattern to create the object. The
classes in question were concrete and there were no associated
interfaces. I don't see what this buys you. I would have simply uses
the concrete classes constructor. I agreed to do it this way because
there may be some benefit that I don't know about. We didn't have time
to argue about it. So I did it using a factory and thought I would
raise the question here to find out what I am missing about this.
At no time are interfaces being used and the factory still needs to be
supplied with all the data that I would have passed via the
constructor. Every time one of these objects has to be created the
factory is used so instead of calls to the constructor being sprinkled
throughout the code, calls to the factory create method with the same
arguments as the classes constructor are sprinkled throughout the
code. So if the constructor argument list changed I would have to
change its invocation in only one place, the factory, but I would also
have to change all the places where the factory create method was
invoked since this would change too.
Regards,
Andrew Marlow
java but a question about programming generally. [if there's a better
newsgroup please let me know which one!]
I am not sure why some people advocate using the factory design
pattern to create instances of objects where the constructor could be
used just as easily (IMHO). I am aware of the Abstract Factory design
pattern (AFDP) in the GoF and I do agree that AFDP has its uses. But
what is being advocated (not by me) in this case is a non-abstract
factory.
Recently I have been working in an agile envirornment and on two
separate occasions my pair partner (a different person each time)
stopped me from creating an object via its constructor and got me to
use the non-abstract factory design pattern to create the object. The
classes in question were concrete and there were no associated
interfaces. I don't see what this buys you. I would have simply uses
the concrete classes constructor. I agreed to do it this way because
there may be some benefit that I don't know about. We didn't have time
to argue about it. So I did it using a factory and thought I would
raise the question here to find out what I am missing about this.
At no time are interfaces being used and the factory still needs to be
supplied with all the data that I would have passed via the
constructor. Every time one of these objects has to be created the
factory is used so instead of calls to the constructor being sprinkled
throughout the code, calls to the factory create method with the same
arguments as the classes constructor are sprinkled throughout the
code. So if the constructor argument list changed I would have to
change its invocation in only one place, the factory, but I would also
have to change all the places where the factory create method was
invoked since this would change too.
Regards,
Andrew Marlow