Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ADT and interface

 
Lisa Cook
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Lisa Cook
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic