while designing my application for a Educational Institute. I created a User Requirement Specification. I am facing some fundamental problems befause there are no hard and fast rules for identifying classes and its members. a programmer is flexible to choose what he/she wants but then they are unaware of the pitfall to be discovered later due to poor design. I fear this therefore i wish to ask these questions.
In my application i want to have a method that will generate (get) the Chapter
Test. lets say i name this method getTest(). Where should i place this method in the Chapter class or the Test class. taking of Object oriented real world model every chapter will have a test and we may also say Test class will have a getTest() method. I mean
view plaincopy to clipboardprint?
class Chapter{
int ID;
String name;
Chapter(int ID, String name){
this.ID = ID;
this.name = name;
}
ArrayList getTest(){
//fire Query to fetch Questions from database for chapter ID = this.ID
return listOfQuestions;
}
}
class Chapter{
int ID;
String name;
Chapter(int ID, String name){
this.ID = ID;
this.name = name;
}
ArrayList getTest(){
//fire Query to fetch Questions from database for chapter ID = this.ID
return listOfQuestions;
}
}
OR
view plaincopy to clipboardprint?
class Test{
ArrayList getTest(int chID){
//fire Query to fetch Questions from database for chapter ID = this.ID
return listOfQuestions;
}
}
class Test{
ArrayList getTest(int chID){
//fire Query to fetch Questions from database for chapter ID = this.ID
return listOfQuestions;
}
}
what would be more OO approach??? please come up with best of the best logics to come to an answer that we could consider standard for further such problems.