Everything should be made as simple as possible, not simpler.
Abstraction is an evolving concept in my mind. From the obscure notion of a library as a hello world newbie to the concepts of encapsulations, inheritance and polymorphism as I become more fluent with the ideas of object oriented programming. These days I am concerned with how to intelligently wire up abstractions, how to refactor the code I've written into more beautiful patterns and gradually hone my ability as an aspiring programming craftsman.
With the succinct overview of abstraction below I hope that others will be able to refer to this and reinforce their understanding or gain a new perspective - basically the unwritten hope of all blog posts ever! Please take my words with a seasoning of caution as I cannot boast any expertise in this domain, and please, please, contact me when you see a conceptual error - criticism is my fertiliser!
To my mind, this is the crux of abstraction. Make your source code **visually** simpler, though architecturally more complex.
Less lines of code
Abstraction is something that culminates in simple, more concise, more flexible and expressive code.
This leaves us, and our team, with code that is easier to reason about and extend.
Simplified code also has the benefit of being easier to to test and debug as there are either less, or better defined paths to logic.
As we simplify, complexity is moved into independent parts of the system. If we maintain good variable/function/class names our source code becomes even more intelligible.
Simplifying the interface you manipulate
Simplification reduces the lines of code we see, though it is merely hiding detail from us.
We simplify by hiding logic to protect, preserve, extend and reuse it.
This enables us to make (careful) changes to our logic, and deliberately design our logic for adaptability and extension.
Hide multi-use code
Starting with variables, we see early on that programming languages are designed to prevent us from duplicating our effort.
Programming languages are essentially tools for isolating, packaging and reusing our ideas.
Variables, data structures, loops, functions, classes/objects, enable progressive layering of hierarchical structure and logical ordering.
The core principles behind Object Orientated Programming boil down to Encapsulation, inheritance and polymorphism. If you can master these, you are well on your way!
Techniques for creating dry, structured code
Encapsulation: Package, and hide, reusable/shared code into an extendable and callable ‘capsule’ (usually a class).
Inheritance: If many objects share functionality, they should obtain it from a common parent object.
Polymorphism: If that common functionality differs, even a little, the child can override or extend parent functionality.
Notice that, despite both `HumanHabitat` and `AlienHabitat` both representing the same type of thing (CoreHabitat), they output different results. Therefore, we can describe two things that are alike, but give them unique behaviour via polymorphism - cool.
Think of individual gems/packages/modules that you use to enhance a project.
A collection of abstracted code
A library is a group of abstractions bundled into a pluggable unit that we can leverage within our programs
The details within the library are not important, provided it produces the advertised/documented output/effect
Libraries are a great way to remove logic from our systems providing a clear decoupling from implementation details
Now contrast the idea of a library to that of something like **Ruby on Rails** of **Django**. Both of these frameworks come bundled with numerous library dependencies - and thus achieve a lot more!
A collection of libraries
When a group of libraries are harmonised under a particular use case then we have a framework for implementing that use case
A framework provides us an opinionated, well documented, and generally extendable procedure for satisfying a particular problem
Frameworks are a tremendous example of what abstraction can achieve and the power we can yield through well abstracted code
Perfecting oneself is as much unlearning as it is learning.