34.13. Configuring Mappers with a MapperFactory

Similar to previous examples of factories in the case study, the configuration of the PersistenceFacade with a set of IMapper objects can be achieved with a factory object, MapperFactory. However, as a slight twist, it is desirable to not name each mapper with a different operation. For example, this is not desirable:

						class MapperFactory
						{
						public IMapper getProductSpecificationMapper() {...}
						public IMapper getSaleMapper() {...}
						...
						}
					

This does not support Protected Variations with respect to a growing list of mappers—and it will grow. Consequently, the following is preferred:

						class MapperFactory
						{
						public Map getAllMappers() {...}
						...
						}
					

where the java.util.Map (probably implemented with a HashMap ...

Get Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and the Unified Process, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.