I think that almost no one would disagree that the human body is a very complex structure. Most of the complexity is hidden from our view. I would like to make a literal comparison between the human body and abstraction layers, as though the body was defined in software. I want to hopefully connect the dots for many to help convince you of the ultimate importance of a well defined and protected interface.
At the outer-most level, there is the body itself where a small sample of its interfaces are capable of:
- Sensory input is given in the form of the 5 (or more) senses
- Communication can be expressed with a variety of means:
- Speech is expressed with the mouth
- Signals expressed with sign-language
- Emotions conveyed with body language
- Pheremones and other more subtle message transports
- Energy and medications are administered through a finite number of orifices.
- Waste and excrement are ejected through well defined interfaces. (When things leave the body from unexpected orifices, this should be concerning.)
- When the body is sick, it expresses symptoms in many ways. Some of them are only internally detected, others are clearly visible or audible.
Internally, the body is further abstracted by its internal systems, and composed of discrete organs and glands to perform specific purposes. A small sample of some of these systems are listed below:
- Commands are issued by the nervous system.
- Sensory information is received by the nervous system.
- The endocrine system helps regulate the different systems, even indirectly issuing its own commands.
- Energy, waste, and hormones are transferred by the circulatory system.
Value of Interface Boundaries
The interface boundaries provide two very important functions:
Provide Discreet Functionality
Consider one of the bodies organs (objects), the eye. Its purpose is to detect light and send the signals to the brain for interpretation. In order to accomplish this task, smaller interfaces are composited to achieve this. Input through the cornea, output through the optic nerve and other various components for protection and adapting to the environment. While the eye can be used for other purposes, such as identification or even feeling sensations, its basic purpose can be summarized to provide sight.
Interfaces control access to both the data and the implementation.
The cornea and the optic nerve provide access for input and output for the eye. However, these are not the only components that are required to have a properly functioning eye. The Iris, Ciliary muscle, Lens, Vitreous humor, Retina, Fovea, and many other components are contained within the eye. The eye works as a closed system. If the behavior or characteristics of any one of these components changes, it may affect the overall quality of vision the eye is capable of producing. For example, many people see floaters. Floaters are caused by debris or impurities find their way into the Vitrious humor and distort the signals detected by the retina.
I only have a rudimentary understanding of the eye, mostly what can be observed from the outside, and information from a few diagrams. Even though the diagrams I have viewed of the eye are very detailed and depict all of its internal components of the eye, I wouldn’t know where to begin to hook in and create a new type of eye by just looking at the diagrams. There are many interconnected components to the eye that do not directly contribute to providing sight. However, if these components are compromised, the eye may no longer provide reliable information to the brain or cease to function altogether.
Now consider what it means to violate these interfaces. I already pointed out what happens when the Vitreous humor in the eye is contaminated. Let’s consider the internal regulatory systems of the body. Under natural circumstances, the only way to interaction with the nervous system is through the 5 senses.
Doctors have invented ways to get around that:
- Ingest medications
- Input validation is important. If you cannot control the input, you may no longer be able to control the output either.
Inject chemicals into your system with hypodermic needles.
Brain surgeons can stimulate regions of the brain with a probe to induce laughing, searching kayak.com other behaviors and actions during surgery
Generally, we get to elect when and who we let violate our natural interfaces. I wouldn’t want just anybody reaching in and tickling your kidneys.
Inheritance is such a valuable and widely abused tool. The topic is so broad many blog entries could be devoted to inheritance. Therefore, I will leave the specifics for another time, and just give you this thought.
Parents interfaces are completely protected from access even to their children. I trust my children even less than my doctor to monkey with my internals. .
Think of your objects as living organisms when you define the interfaces and create the implementations. Imagine you were that organism and consider what is required to guarantee the integrity of your object.
Take advantage of strict interfaces to:
- Protect access
- Verify input
- Encapsulate details
- Abstract complexity
Would you trust the invariants of your design to be left up to users that interact with you?