abstract data type

What is a difference between an abstract data type and an object.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


An object is an instance of a data type.  For example in

class SomeClass

SomeClass A;
SomeClass B;

"SomeClass" is a data type.  That is, it is not data, it specifies a type of data, just like int or char do.  "A" and "B" are objects.  They ARE the data and they are of the type "SomeClass"


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
An "abstract data type" is a data type, but it is a data type that cannot be used _directly_ to create objects.   Thus it is not directly useful (A data type that can't be used to create objects is not bery useful), but it may be used to create other data types and some of those data types may be "concrete" (instead of "abstract") and thus may be used to create objects.

In C++, only a class may be an abstract data type.  An abstract data type class, usually called an "Abstract Base Class" or ABC, is created by specifying a pure virtual function.  This is a function that must be defined in a derived class.  One a derived class that specifies an implimentation of this pure virtual function (and any others) will be "concrete".  For example.

class Abstract
   virtual void DoSomething() {} = 0; // Pure virtual function.

class Concrete : public abstract
   virtual void DoSomething() {}; // virtual function defined.

Abstract A; // ERROR. Abstract is an ABC
Concrete C; // Okay.

Let me know if you have any questions.
Thanks for your comments.

Although your comments were relatively detailed, thanks for that, but still there is some confusion.

First of all dont go in Virtual funtions.I know them but it is better to leave them for future discussion.

Now what you are trying to say is that abstract data type can be used as a data type but can't be used as an instance (object).

OK then my next question is that how are we going to define abstract data type and call it within some class or functioin. your above explanation technique was excelent, but don't go into virtual functions.

Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

This is redgreenred's question.  You should ask you own question.

>> abstract data type can be used as a data
>> type but can't be used as an instance (object). .  
It cannot be used to create objects, that is objects of its type cannot be created.  So it is not a "concrete" or "complete" (my term) data type.  Its only value is that it can be used as a base class of other data types.  

>> above explanation technique was
>> excelent, but don't go into virtual functions
That's the only way in C++.  
redgreenredAuthor Commented:
thank you both tparvaiz and nietod,

It seems that I've got it my answer. Let me review it again.

abstract class can only be a base class and cannot be used anywhere else.

Is that the case only for C++ or with all other languages.

nietod! can you tell me, how do we declare abstract class?

>> cannot be used anywhere else
Not completely true.  The abstrcat type may not be used to create objects of the abstract type.  But the type may be used in other ways.  Like it may be used to declare pointer an reference types.  i.e you can have a pointer to an object of an abstract type, event though you cannot create an object of this type.  You can use this sort of pointer to point to objects that are of a derived class, like

class AbstractClass
   virtual void Function() = 0;

class ConcreteClass : public AbstactClass;
   virtual void Function() {};

AbstactClass *Ptr; // Pointer to abstract class object.

Ptr = new ConcreteClasss; // Concrete object created, ptr to base used.

>> Is that the case only for C++ or with all other languages.
Is what the case?  

Most languages don't even support objects and some that support objects might not support abstract data types.   But in OOP the term "abstract data type" means a type that cannot be instanciated a an object.  Just not all languages support this feature.

>> how do we declare abstract class?
In C++ the class has to have a pure virtual function.  That's the only way.  If there are no good candidate functions, then make the destrutor pure virtual.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.