The thing I found hard is abstract data type, and also the ADT stack. However, I noticed I have not throughly talked about it yet. Thus, I decide to do some review on it.
First of all, we need to understand what is ADT. ADT is an abstract data type, it is defined by a set of operations(what it does), but without saying how they are implemented. Thus it seems abstract, and makes us wonder, if it cannot be implemented, then why it is useful. The fact is we can but we sometimes do not need to come up with methods and give specific implementation of the method at the same time. If the procedure is separated, then the task is simpler and clearer. Also, some well-known ADT can be used frequently by many people, and similarly, an algorithm can be used in many implementations. Next, there are two unfamiliar words distinguish the "idea of operations" and "implementations of operation". The first one is called the provider, the second one is called the implementor. The division of the work accelerates our process in programming. Another word is "interface", which means a set of operations that define an ADT.
One ADT we have talked for a lot of times is Stack. It consists of four operations: 1) __init__; 2) push; 3) pop; 4) is_empty. The implementation of them is called veneer, because it is very easy and using existing methods. One more thing to indicate, stack has LIFO("Last In, First Out") structure.
Here is how stack is implemented.
class Stack:
def __init__(self):
self.items = []
def push(self, item):
self.items.append(item)
def pop(self):
return self.items.pop()
def is_empty(self):
return (self.items == [])
(Source: http://openbookproject.net/thinkcs/python/english3e/stacks.html)
Thanks for reading!!
note we've been learning ADT through the whole term. not only Stack is a ADT, Queue, LinkedLIst, Tree are all ADTs.
ReplyDeleteADT is closely related to OPP.
OPP is like a tool to transfer the real world problem to an abstract computer platform. It involves at least these phrases:
- understanding the problem domain
- figuring out what type your might want
- figuring out what features you want your type to have
- writing a class that represents this type
The last step is creating a ADT, so that's what i think ADT is a class that has its attributes, methods and it represents a certain type
Thank you! Relating ADT with OPP is really helpful.
DeleteI really think that any non_buildin way of saving data is an ADT...
Delete