Difference between ADT and Classes?

12,577

Solution 1

The key to the difference is abstract. Think of an ADT more like an interface - a class with only method declarations, no implementation details.

As an example, a Stack ADT defines the basic stack operations like push and pop (but says nothing of how these operations should be implemented), while a Stack class would use either a linked-list or an array to actually implement these operations.

Solution 2

According to Code Complete, ADT is a collection of data and operations that work on that data.

Example for ADT:

List

  • Initialize list
  • Insert item in list
  • Remove item from list
  • Read next item from list

ADT form the foundation for the concept of classes. In languages that support classes, you can implement each abstract data type as its own class. Classes usually involve the additional concepts of inheritance and polymorphism. One way of thinking of a class is as an abstract data type plus inheritance and polymorphism.

Solution 3

An abstract data type (ADT) is a mathematical abstraction of a real world thing and can be implemented in a concrete data type in different languages.

An ADT defines operations for the given type and mathematically expresses their behaviour. Concrete implementations of an ADT can differ from each other. In that way classes are implementing the ADT and methods implement operations.

Classes have a slightly different terminology than ADTs and add other characteristics, like:

  • they for example may live in packages
  • their members are called attributes and methods
  • attributes and methods have a certain visibility constraint

And methods:

  • can be abstract, too. but then, their behaviour isn't defined - only their method signature - an inheriting concrete class must provide an implementation

Don't confuse abstract data types with abstract classes in a concrete language.

Share:
12,577

Related videos on Youtube

ajknzhol
Author by

ajknzhol

My name is Ajay Kumar N. I am ajkumar25 at Github and @ajkumar25 at twitter. You can also reach me via email. I try to contribute to society by striving to create great software products that make people's lives easier. I believe software is the most effective way to touch others' lives in our day and time. I mostly work in Python, I do not pigeonhole myself to specific languages or frameworks. A good developer is receptive and has the ability to learn new technologies. I also often contribute to open source projects and beta test startup products. I'm passionate about making people's lives better through software. Whether it's a small piece of functionality implemented in a way that is seamless to the user, or it's a large scale effort to improve the performance and usability of software, I'm there. That's what I do. I make software. Better

Updated on August 28, 2022

Comments

  • ajknzhol
    ajknzhol about 1 year
    ADT is the set of operations. ADT's are mathematical abstractions.
    

    Does this mean that ADT are same as classes or am i confusing both together ?

  • subin sahayam
    subin sahayam about 3 years
    Ok. So the Stack class will be my data structures + object-oriented concepts that I use for implementation like a linked list or an array. But, when we import a package with all its classes, aren't the implementation hidden from the user importing the package? Wouldn't that make class names as ADTs too? I hope my question is clear.
  • S M Vaidhyanathan
    S M Vaidhyanathan about 3 years
    @Bernhard But, Why can't a class be considered as an ADT ?
  • Bernhard Barker
    Bernhard Barker about 3 years
    @SMVaidhyanathan Once you have a concrete implementation, it's by definition no longer abstract (and thus can't be an abstract data type). It's like the difference between a list of properties (like texture, what it looks like and what it's made of) that defines what ice cream is (which would be like an ADT) and a recipe for how to make a particular type of ice cream (which would be like the class). The actual ice cream would be like the object.
  • Bernhard Barker
    Bernhard Barker about 3 years
    @subinsahayam The fact that you can call one of the methods of a class or one of its objects and it would behave in a certain way arguably means it's no longer abstract. The implementation details are still there, and it affects how the class and its objects behaves and possibly what other methods it has, even if you can't directly see the implementation details.
  • U. Windl
    U. Windl over 2 years
    You mean "a set of types"?
  • tessiof
    tessiof about 2 years
    This should be the selected correct answer!