Sunday, April 5, 2015

Week 7: Abstract Data Types

     ADTs in object-oriented programming are very interesting to me (if a bit frustrating).  They are "abstract" because they can be modified later on.  So, they define the methods of a class and what they should do, but there is no specific implementation.  We take a set of data and define the operations that can be used on the data, but we don't define it in a specific way (yet).  It allows for a simpler understanding of an algorithm and the creation of similar classes.  It also allows programmers to keep track of more than one instance of a collection of items.  So, we know what it's supposed to do, but the real question is how.  Some ADTs included within Python are strings, sets, lists, and dictionaries.
     Stacks are a prime example of ADTs.  They are a collection of elements, meaning that multiple elements can be included.  It's a list, but it can only be modified in two ways: push and pop, which adds a new item to the stack and removes an item from the stack, respectively.  However, pop only ever returns the last item added.  Yet, there is no one way to implement these methods, and they can be interpreted different ways; for example, pop can remove or return the most recently added item.
     Ergo, ADTs can be implemented in a few different ways.  They must be implemented to allow for any foreseeable action to take place--for example, if we're creating a class of points, we should create methods that create the point, add points, return the point, etc.  We have often used ADTs in class, when we make subclasses and the like.  We define methods in one class and the next inherits it or modifies it in some way.  We've also used them in labs; for example, queue was an example of an ADT.  It had enqueue and dequeue, which people implemented in different ways.  It was a helpful exercise that allowed us to experiment with different ideas, and it was interesting to see how different people had completed the lab.  I finished early with a simply implementation, but someone beside me had lots of trouble trying to use a more complicated function.  It all depends on the programmer, I believe, to make efficient use of ADTs.

3 comments:

  1. Excellent and very clearly worded explanation of ADTs. I personally chose not to write on this topic because I thought it would be difficult to convey in words, but I'm glad to see that wasn't a problem for you!

    ReplyDelete
    Replies
    1. Haha, you have no idea how hard it was. x3 I was really struggling on how to explain it properly. I'm glad you liked it!

      Delete
  2. Really cool to read an ADT post since I focused on OO Design :) This definately helped to clear the line between ADTs and OO Design since before I felt as is there was considerable overlap and the label of ADT could be applied to any class that you make, rather than specific data structures like Trees

    ReplyDelete