redgreenred
asked on
abstract data type
What is a difference between an abstract data type and an object.
Thanks
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
Thanks
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.
Thanks
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++.
>> 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++.
ASKER
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?
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.
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.
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.