Sponsored By Aspose - File Format APIs for .NET

Aspose are the market leader of .NET APIs for file business formats – natively work with DOCX, XLSX, PPT, PDF, MSG, MPP, images formats and many more!

Data Abstraction Defined

This is the second of a 4 part series, for those of you new to object-oriented programming, discussing the 4 major principles of an object-oriented language: Data Abstraction, Encapsulation we’ve already discussed, Polymorphism and Inheritence. Data abstraction is the simplest of principles to understand. Data abstraction and encapuslation are closely tied together, because a simple definition of data abstraction is the development of classes, objects, types in terms of their interfaces and functionality, instead of their implementation details. Abstraction denotes a model, a view, or some other focused representation for an actual item. Its the development of a software object to represent an object we can find in the real world. Encapsulation hides the details of that implementation.

Abstraction is used to manage complexity. Software developers use abstraction to decompose complex systems into smaller components. As development progresss, programmers know the functionality they can expect from as yet undeveloped subsystems. Thus, programmers are not burdened by considering the waysin which the implementation of later subsystesm will affect the design of earlier development.

The best definition of abstraction I’ve ever read is: “An abstraction denotes the essential characteristics of an object that distinguish it from all other kinds of object and thus provide crisply defined conceptual boundaries, relative to the perspective of the viewer.” — G. Booch, Object-Oriented Design With Applications, Benjamin/Cummings, Menlo Park, California, 1991.

Lets look at this code for a person object. What are some things that a person can do? Those things must be represented here in our software model of a person. Things such as how tall the person is, and the age of the person; we need to be able to see those. We need the ability for the person to do things, such as run. We need to be able to ask the person if they can read.

Public Class Person

Private _height As Int16
Public Property Height() As Int16
Return _height
End Get
Set(ByVal Value As Int16)
_height = Value
End Set
End Property

Private _weight As Int16
Public Property Weight() As Int16
Return _weight
End Get
Set(ByVal Value As Int16)
_weight = Value
End Set
End Property

Private _age As Int16
Public Property Age() As Int16
Return _age
End Get
Set(ByVal Value As Int16)
_age = Value
End Set
End Property

Public Sub Sit()
‘ Code that makes the person sit
End Sub

Public Sub Run()
‘ Code that makes the person run
End Sub

Public Sub Cry()
‘ Code that make the person cry
End Sub

Public Function CanRead() As Boolean
‘ Code that determines if the person can read

‘ and returns a true or false
End Function

End Class

So, there we have started to create a software model of a person object; we have created an abstract type of what a person object is to us outside of the software world. The abstract person is defined by the operations that can be performed on it, and the information we can get from it and give to it. What does the abstracted person object look like to the software world that doesn’t have access to its inner workings? It looks like this:

You can’t really see what the code is that makes the person run. This is encapsulation that we discuseed last week.

So, in short, data abstraction is nothing more than the implementation of an object that contains the same essential properties and actions we can find in the original object we are representing.

Currently listening to: All Along the Watchtower – Dave Matthews Band with Phish

This entry was posted in Patterns and Practices. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

2 Responses to Data Abstraction Defined

  1. Kavitha says:

    Very good explanaion of data Abstraction and encapsulation.

  2. Balaji says:

    Thanks Mr.Raymond,

    This article gives a nice introduction about abstraction.I had some confusion on abstraction and encapsulation.You have given good explanation with simple example.

    Really thanks a lot…


Leave a Reply