0

What is the difference between the mapper and the collection pattern in PHP?

Tim Post
  • 32,014
  • 15
  • 104
  • 162

1 Answers1

3

Mappers (assuming that you are referring to data mapper pattern) are structures that abstract the storage logic. It's where you SQL queries, SOAP/REST calls and other interaction with storage mediums happens.

Collections are not really a pattern as such. It is usually an unspecified container for an set of objects. A common use of it is for groups of domain objects, which belong to separate layer, that handles the business domain logic.

In complicated applications you usually will have at least few data mappers, that are used to exchange information between storage and the collection.

For some code examples you can check this answer.

TL;DR

Only common thing for mappers and collection is that they both tend to be objects.

Community
  • 1
  • 1
tereško
  • 56,151
  • 24
  • 92
  • 147