Factories and Builders [was Re: lambdak...]

Gregory Ewing greg.ewing at canterbury.ac.nz
Fri Jan 16 22:25:37 CET 2015

Steven D'Aprano wrote:
> I've never really understand why "abstract factory", "factory method"
> and "builder" are considered different design patterns. They're variants on
> the same idea.

I think it's because they address different problems. Factories
are for hiding the details of how an object is constructed.
Builders are for working around the fact that there are no
keyword arguments in your language.

Builders are sometimes also used for algorithmic reasons;
e.g. Java's StringBuilder exists to save you from O(n**2)
behaviour when creating a string from many small parts.

Factories of various kinds can be useful in Python;
builders, not so much.


More information about the Python-list mailing list