When an abstracted characteristic or property is exposed by an abstraction layer and then accessed and explored by the upper layers.
A real world scenario of an abstraction leak
Lets imagine a system design based in the classical layered architecture: UI + Business + DAO layers. The user interacts with the UI and the UI issues commands to the Business layer and then the business layer converts human commands into data access commands, which are then converted by the DAO layer into database operations.
The DAO layer has a well defined purpose in the architecture: it abstracts the data persistence technology and infrastructure to the Business layer.
A clear example of abstraction leak in this scenario, would be a method in a DAO class that allows passing a SQL query for execution. The DAO class would be exposing the persistence technology to the upper layer, breaking the abstraction it is supposed to provide.
Some devz would find it inoffensive, but, one single method exposing internal or lower level characteristics can ruin the entire abstraction. How could such a single method ruin the entire abstraction layer?
The upper layer will be assuming that the DAO layer is operating on top of a Relational database (or any other database that supports SQL querying). More than assuming it’s a relational database, the upper layer will also know the database schema, the columns of each table (even the ones that weren’t exposed by the entities).
You are practically removing the abstraction layer, leading your application to an architecture like this one:
If this is not bad for you yet, let me add more salt to the pot: How easily can we swap the DAO Layer implementation? How cheap would it be? Okay, that might be a very dramatic question, but what if we just want to rename a database column or even a table? How many code files would we have to modify? Would we know where to start from? You might have figured out the impact of an abstraction leak by now, so I guess it’s time for me to stop adding salt to the pot.
Remember: The Abstraction leak phenomenon can happen anywhere there is an abstraction layer. Be careful to not jeopardise someone else’s work.
About Abstraction Leaks, this is all i had to discuss. It’s always a pleasure!






Comentários Recentes