- Notifications
You must be signed in to change notification settings - Fork39
Concretion
Concretion is when in order to use something we need aconcrete knowledge about the thing.
Dependency Inversion Principle: Entities must depend onabstractions, not onconcretions.
The common way to apply DIP to Object-Oriented programming is that when a class depends on another class, it should not depend on concrete instances of the other class. Rather, it should depend on anabstract interface implemented by that class.
A more abstract way to handle dependency between entities is to invoke code bysending a message to an object. The only required knowledge is the name of the message, represented with a generic entity (e.g. a string).
In a sense, the Clojure idiomjust use maps is an application of the Dependency Inversion Principle todata. Representing data with a data class or a data record is aconcretion: The only way to access data is via the class methods or record members.
When we access data through the methods of an interface, it's a bit less concrete. But still, we can access data only through the methods defined in the interface.
A more abstract (less concrete) way to represent data is with generic maps. In order to access data in a map, the only required knowledge is the field name, represented with generic entities like strings (or Clojure keywords).
| Code | Data | |
|---|---|---|
| Concrete | Concrete class | Concrete record |
| Less concrete | Abstract class | Abstract class with getters |
| Most abstract | Message passing | Generic map |