What is Abstraction

Abstraction is, according to John V. Guttag

The essence of abstractions is preserving information that is relevant in a given context, and forgetting information that is irrelevant in that context.

You can see abstractions everywhere in day to day life. Take the example of medical doctors. A neurologist is interested in brains and nerves. A cardiologist works on heart and blood transport lines. But all these specialists are working on human system. So the neurologists abstraction is the nervous system. It is abstracted away from all other medical specialists. Cardiologists knows how brains and heart are related and how to keep the brain functioning when he does something to the heart. Cardiologists does not care or may not be intersted in how brain stores memories or perceive smell.

Another example of abstraction is databases. For a database engineer, data is tables and columns and records. And then there are relationships between tables. She is never worried about how data is stored. When a record is read, ultimately the data should be read from the storage. The engineer who is implementing the low level libraries to read from storage does not care about data records and relationships. His abstraction is the storage device and pushing bits and bytes of data to and fro to the storage device. So the database engineer is abstracted from this. A network engineers abstraction is a stream of bytes. If data is transmitted over network to database, the same stream is perceived as records by the database engineer. So all these people are dealing with bytes of data but they have different abstractions.

In essence, abstraction hides the complexities and provides the user an interface to work with the object. Every class in C# is an abstraction. Threading class abstracts all the complicated code and provide the consumer with an easy way to spawn a thread. Look at the following code.

Worker workerObject = new Worker();

Thread workerThread = new Thread(workerObject.DoWork);


When the third line is invoked, a separate thread is launched and the function DoWork is executed. Under the covers a lot of things are happening. A separte address space is created for you. Thread local storage is created and when you issue a Start, thread actually become functional. But all these things are abstracted from you.

Abstraction may be mistaken for encapsulation. But they are not the same. Infact they compliment each other. Abstraction focuses on the observable behavior of an object. Encapsulation focuses on the implementation that gives rise to this behavior.

Grady Booche's Object Oriented Analysis and Design With Applications is great book on OOP.

We offer one on one C# training,SQL training,WCF training,WPF training,WinForms training, MVC training, ASP.NET training, Ajax & Javascript training. Please see the contacts page