All the Object Oriented Design Principles hover around the use of abstraction in software design for reusability and flexibility. However, the underlying implicit advantage of abstraction is simplification. Reusability and flexibility are not possible only unless the issue at hand can be understood and simplified, and abstraction is the way to do it.
In computer science, abstraction is a mechanism and practice to reduce and factor out details so that one can focus on a few concepts at a time.
Why? Because Details Create Complexity
An idea at the core is simple. Implementation of an idea will involve, everything from technical details to finance to management to marketing. All these are important for a successful execution, but not for understanding the idea itself. Abstraction can strip out details and provide a minimalist version of the idea which is easier to understand. This minimalist version includes only the factors which form the value, this also helps in realising the necessary factors. This does not mean that the details should be ignored altogether, but only for the purpose of understanding. Once the concept is understood, details also come across much easier.
Let us consider an example. The modern banking involves multiple channels of accessing your account – in addition to physicall visiting the bank, you can use the internet banking and phone banking facilities. If you visit the bank, your account number is used to identify you and signature to authenticate. Similarly the combination of username/password and account number/pin number is used when using internet banking and phone banking respectively. Conceptually, these are just different ways of saying that the bank needs to identify you, the customer. This seems to be much simpler and time saving than specifying the details for understanding. When an additonal channel is required, say ATM machines, the process of identification will be still required, but can be carried out in a different way. It is not difficult to realise that again this can lead to a better reusability. I have said this before, the abstract levels really represent the concept or the idea. Abstraction decouples the purpose from the means of achieving it. Interface is a classic example.
Levels of Abstraction
Abstraction is useful not only for understanding, but also explaining to someone. The right level of abstraction can avoid information overload and get the point across better.
The levels of abstraction are inversely proportional to the levels of details. When communicating with someone, the level of abstraction used should be according to the audience. The different levels of abstraction model the same information and processes differently. There are two aspects to consider:
- existing knowledge of the audience
- details required for performing the task or communication
Depending on the role one plays in the system, the details of information available are different. As a customer of post office, all you know is that a valid address and a stamp is required to post a letter. Whereas a postman will have many more intricate details about how the letter will be routed to the addressee. However, if the postman is talking to you and mentions the intricate ways of routing the letters, you will get baffled by it. You will not understand as you do not have the prerequisite knowledge, and more importantly, you need not know that. Similarly when you are talking to the postman, you cannot have to write a valid postal address that the postman can understand, the address cannot be “To Mom” or “To My Niece”. In both the cases, both of you had to hide some details to communicate effectively so that some task can be done.
The right level of abstraction includes only the necessary details, and excludes the others.
The categorical dual of abstraction is encapsulation.
While designing software systems, engineers can use different levels of abstraction for a design to verify if it complies with the specification. This can help in identifying faults much earlier than if they were identified in the concrete versions.
Abstraction helps Innovation
Since abstraction can isolate the end from the means, it is easier to visualise the different means possible for achieving the end. It is not only true to find the best solution, but also to find multiple solutions. Like the multiple channels used in banking example, the abstraction will be helpful in implementing new such channels.
Abstraction in Software Engineering
As a software engineer, abstraction is seen everywhere – architecture, code, design, even communication with team members. There are two types of abstraction in software engineering:
- Control Abstractoin is what differentiates high level programming languages from the microprocessor programming. A function/method call in a high-level language translates to multiple complex steps in assembly language which a programmer need not know. The libraries or APIs that we see are types of control abstraction.
- Data Abstraction: separates the abstract and concrete properties of objects. The abstract properties provide reusability and extensibility. We have seen its applications in the Class Design Principles.
Abstraction and Generalization
Generalization serves the purpose of creating groups. The purpose of generalization is not always simplification, it can be to apply the behavior of a group to its members.
Concept A is a (strict) generalization of concept B if and only if:
* every instance of concept B is also an instance of concept A; and
* there are instances of concept A which are not instances of concept B.
Equivalently, A is a generalization of B if B is a specialization of A.
For instance, animal is a generalization of bird because every bird is an animal, and there are animals which are not birds (dogs, for instance).
Software engineers should be differentiate between abstraction and generalization, especially because same techniques (inheritance) are used to achieve both.
Some more instances of abstraction in everyday life
- Your music system box is an abstraction of what is involved in converting the data on CDs to music. This can be applied to any electronic device we use today
- Your computer desktop is an abstraction of the internals of the operating system.
- Your demat bank account is an abstraction of the headache of manually buying and selling stocks.
- The customer service at your departmental store is an abstraction of what happens internally when goods are exchanged.
There are probably several more, but all of these provide just enough details to make them usable, nothing more than that and nothing less.
Copyright Abhijit Nadgouda.