There is a question in an exam paper of mine which asks to create an ADT for a given scenario. And it asks only to write abstract methods instead of concrete implementations.
It required to represent the time table in a school. School has to keep track of which period is allocated for each subject taught. Subjects could vary according to the grades and these subjects can change over time.
I can't understand what should be in the ADT methods. And I want to know how to use that ADT in a time table class.
Defining an ADT in general can be treated as an act of translation of user requirements to the specification of behavior that can be expressed in the programming language (java in this case).
So here you go:
Obviously You need some abstraction to define the time table, so you'll create a class / interface to "express" this.
The behavior of this abstraction should be expressed by adding methods to this interface or a class. So you read the user requirements (in this case the "user" is your teacher :) ):
School has to keep track of which period is allocated for each subject taught.
Ok, how do you represent the "subject taught"? Probably it deserves its own class or maybe its just a string. Or maybe each subject has an identification number? Its up to your design.
Now, what is a period? Is it identified by some class Period
or you model it is a pair of startTime
/endTime
?(hint, in java you can't return two objects from the same method at once) When you have an answer to all these questions, you can define a method that will accept the subject and return the period. Add this method to the abstraction of your time table. You've specified the behaviour!
The second sentence is a requirement that is rather an explanation of how the subject should look like.
Subjects could vary according to the grades and these subjects can change over time.
Now you know that subjects must probably contain grades, and subjects are changing over time. If this point is not really clear (to me it doesn't frankly, I believe you can ask/find additional clarifications in the exercise doc) but in any case, I think I've described the process you should get through when designing the ADT.