Wednesday, 25 February 2015

Abstract Data Types (ADT) Part 1: The Concept

Last post, I talked in depth about OOP. More specifically, I talked about the modularity and inheritance which makes OOP powerful. For modularity, you need to have specifications for each of the parts.

For example, let's talk about building a computer (hardware wise). There are many components, but let's talk about the most important few: motherboard, CPU, GPU, and RAM. Computer is modular, due to the specific way in which they connect to each other. Each of their roles are defined and thus the motherboard knows how to interact with the RAM. There exists some interface. Due to this defined interface, many different RAM can connect to the same motherboard, even though the exact architecture and exactly how it is done may be different from RAM to RAM. For example, you know that it must have a particular pin dimension to connect to the motherboard. When given input X and the query Y, two different specific RAM must know that query and also provide the same answer for the other parts interfacing it to understand the output.

What does the general RAM not know? A lot of things of course are not defined, but one such is RAM speed. There are specific details that the motherboard does not care about. Once the detail matters to the motherboard, the detail must be specified at the interface level to maintain modularity. With RAM for example, this interface is given a name such as DDR2 or DDR3. This has information about which RAM can be used for certain CPU.

Let's shift gears a little and think about how this relates to ADT. The general RAM is like an ADT, while the ADT's subclasses (which should be instantiated) is like a specific RAM that can be bought like Desktop Momory Model F3-10600CL9S-4GBNT. All the tasks and the way it performs those tasks (and in this case also the way it interfaces with the hardware ie. the pin connections) is specified in that general RAM so that specific RAM can follow them. In this case, the motherboard or whatever is interacting with the RAM is the client. Notice how the client does not need to know how the memory works. Only the operations and the results of those matter.

I mentioned above that ADT's are like specifications for the interface. This is related also to inheritance in that the subclasses inheriting from ADTs in a sense are promising to follow these guidelines. It's like companies advertising their RAM as DDR3. I think of inheritance from ADT as being a claim to follow these specifications. X which inherited from Y is an instance of Y. Thinking about our RAM, the GBNT is an instance of RAM.

Modularity in general is very powerful. In the context of computers, the most obvious benefit as a consumer is easy upgrading and fixing. Your GPU isn't good enough to support the new game in high resolution... just change that. You don't need to buy a brand new computer. It's the same with programming. In class, we are making a two player game where one of them is a computer. By using a strategy class, we were able to "upgrade" from a random move chooser to a minimax strategy where the best move can be chosen.

For fixing, suppose your GPU got some electrical shock and doesn't work anymore. Same idea. You can just get a new GPU rather than spending more money on getting everything. Similarly for software development, you only need to debug and fix what's not working. You don't need to spend time and effort fixing everything.

In addition, parallel development is possible now. In the context of computers again, the CPU making companies do not need to know about how memory will be stored etc. As long as the two development teams agree to do things in a certain way (establish an interface), they can develop things separately. In the context of programming, it means many people can work on the project together.

I feel like I've rehashed a lot of the material from my previous post but with a better conceptual illustration. For a summary of some of the OOP terms and ideas, see my previous post.

For the next post, I want to provide an example of very famous ADT we covered in class.

No comments:

Post a Comment