Introduction to iOS App Design Patterns p40
-
About the dependency relationship between modules
-
It is worst if the upper and lower levels know about each other
- This is called pathological coupling
-
It is better for the upper level to not think about anything and let the lower level handle it
-
However, there are times when the upper level needs to access the lower level
-
To resolve this contradiction,
- The lower level (user) becomes a Protocol
- If the upper level (provider) wants to access the lower level, it should conform to the protocol instead of accessing the actual implementation
-
For example, let’s say there is a domain layer and a database management layer. (The domain layer is the upper level)
- The program in the domain layer doesn’t want to be concerned about the database
- Therefore, the domain layer is protocolized
- The database depends on that protocol