Abstraction vs. Encapsulation

Previously, I wrote about a concept called encapsulation. Today, I'd like to make a clear distinction between two closely related, yet subtly different, ideas.
Encapsulation: A Quick Refresher
Encapsulation is the hiding of the internal complexity of a process or state. Its primary focus is on hiding away the implementation details.
Abstraction: Hiding Complexity
While encapsulation is inherently inward-facing or "private," abstraction is public or outward-facing. The main focus here is creating simple interfaces for the more complex behavior of the process underneath.
Think about a car. To drive it, you only need to know how to use the steering wheel, pedals, and gear shifter. You don't need to understand how the internal combustion engine works, how the transmission shifts gears, or the complex electrical systems. The manufacturer has abstracted all of that complexity away from you.
In Python, we use classes and methods to achieve abstraction. We create methods that perform a task for us without needing to know every step involved.
The power of abstraction is that it makes our code easier to read, use, and manage. It allows us to build powerful tools without getting bogged down in the details.
In summary, encapsulation is about hiding complexity to protect it, while abstraction is about providing a simple interface to use that hidden complexity.






