CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Raymond Lewallen

Framework Design, Agile Coach, President Oklahoma City Developers Group, Microsoft MVP C#, TDD, Continuous Integration, Patterns and Practices, Domain Driven Design, Speaker, VB.Net, C# and Sql Server

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
        Get
            Return _height
        End Get
        Set(ByVal Value As Int16)
            _height = Value
        End Set
    End Property

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

    Private _age As Int16
    Public Property Age() As Int16
        Get
            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


Comments

TrackBack said:

# February 22, 2005 11:34 AM

TrackBack said:

# February 24, 2005 5:35 AM

TrackBack said:

# March 15, 2005 6:03 AM

TrackBack said:

# March 16, 2005 8:14 PM

David Hayden said:

 I received an email message via this blog for some help in identifying good recources on OOP and...
# January 18, 2006 7:16 PM

Balaji said:

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...

balaji
# August 12, 2006 6:16 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Raymond Lewallen

Working primarily in the public sector during his career, Raymond has designed and built several high profile enterprise level applications for all levels of the government. Raymond now works as a solutions architect for EMC. Raymond is an agile coach, Microsoft MVP C# and also president of the Oklahoma City Developers Group and Oklahoma Agile Developers Group. Raymond spends a lot of his time learning and teaching such things as Test Driven Development, Domain Driven Design, Design Patterns and Extreme Programming practices and principles, to name a few. Raymond is also an advocate of Alt.Net. Raymond is primarily a framework guy, so don't ask him anything about UI :) Check out Devlicio.us!