I just started reading The Pragmatic Programmer e2. I came a cross the topic of avoiding Duplication with Data Sources, which I did not fully understand. The pragraph reads as follows:
Many Data sources allow you to introspect on their data schema. This can be used to remove much of the duplication between them and your code. Rather than manually creating the code to contain this stored data, you can generate the containers directly from the schema. Many persistence frameworks will do this heavy lifting for you.
I did not understand that. How introspection can be used to avoid duplication? and what does he mean by ‘generate the code directly from the schema’? Is there any practical example?
There’s another option, and one we often prefer. Rather than writing code that represents external data in a fixed structure (an instance of a struct of class for example), just stick it into a key/value data structure (your language might call it a map, hash, ditionary, or even object). On its own this is risky …. we recommend adding a second layer to this solution: a simly table-driven validation suite that verifies that the map you’ve created contains at least the data you need. Your API documentation tool might be able to generate this.
Does this mean I should not create a model representation of the tables in RDBMS? How key/value will be represented? and how does this help avoid duplication with data sources?
I am from Java background, but I have not been coding for a while now. I am not sure if that is the reason I cannot understand this. I’d appreciate if you could provide the explanation with practical example