File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes ADT and interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ADT and interface" Watch "ADT and interface" New topic
Author

ADT and interface

Lisa Cook
Greenhorn

Joined: Oct 17, 2003
Posts: 6
I am very lost over ADT's. From what i understand, ADT's will hid all implementations, which is the data structure right? So then the ADT is basically the core operations (specifications) that a client program will have to use? But, then what does the interface part come in..??
For example i have this piece of code:
public class List implements ListInterface{
.....
public void add (Object newObj){.....}
......
}
THis is the file that actually implements the fuctions you want the list to do
What i dont understand is this .java file:
public inteface ListInterface{
....
public void add(Object newObj);
....
}
Why is it necessary..?? Is it always needed when you create an ADT?
I mean this would work just as fine right?
public class List{
.....
public void add (Object newObj){.....}
......
}
[ October 17, 2003: Message edited by: Lisa Cook ]
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 805
Hi, Lisa -
Welcome to JavaRanch!
An Abstract Data Type (ADT) is just a user-defined data type, called a class, which is composed of data elements (fields) and methods (functions). In Java a class can only inherit from one parent class; this is called single-inheritance. By using interfaces, we can "trick" the JVM into letting us use a pseudo-multiple inheritance.
The data members/fields are the data in the ADT; the methods are the interface (using the OOP meaning here). By hiding your data, and making other classes use methods to get or set a value in your data member(s), you can guarantee data integrity and also simplify redistributing the class if you have to change how the data is actually implemented because users of your class won't have to change how they access the data. These methods, taken together, form the ADT's Application Program Interface, or API.
On reading this reply, I'm not sure if I answered your question or if I just threw mud on your windshield!


Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Lisa Cook
Greenhorn

Joined: Oct 17, 2003
Posts: 6
I think i am confused because i am confusing the "interface" terms. The example i provided above, i took out of my textbook, and it didnt really explain why a ListInterface.java file was created for the list.
If i use the list ADT in my class, then i would be doing this:
public class newList{
....
List myList = new List();
myList.add(myObject);
....
}
This is the way i am suppose to use the List ADT right? If so, then what is the need for that ListInterface.java file?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ADT and interface