Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with OO Approach?  RSS feed

 
shukla raghav
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Posts: 21087
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please Use Code Tags.
 
Daniel Matthews
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you have just answered your own question "Object oriented real world model every chapter will have a test..." This is composition. Your "getTest" method is simply encapsulating your "test" member
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post each question only once. I am locking your other thread.
 
Geo Kinkladze
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The basic test that I always try and remember is the "Has a relationship" i.e.

Does Chapter have a test (or set of tests) or does a test have a chapter (or set of chapters). It would seem more logical to me that a chapter has a set of tests, certainly from all the books I seem to be finding myself looking at these days.

 
shukla raghav
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Geo Kinkladze - yes you are right but see there is a very subtle difference between the two. It all depends on view point. here the problem depends on how we define an object. We can visualize the object either as "set of Attributes" or "set of Behaviours" lets apply both the approaches.

1. Object as set of Attributes

Test class will have attributes such as Max marks, Max Time, Test ID, List of Questions, Chapter ID

Chapter Class will have ChapterID, Chapter name, Topics Covered. (We cannot logical visualize Test by any means as a part of a chapter. chapter can be considered as set of concepts thats all )

2. Object as set of Behaviors

Test class have behavior (methods) such as generateQuestionSet(), evaluateTest(), remainingTime(), generateRank()
Lets talk about the last one generateRank(), although it may seem right but according to me its not correct because rank generation is logically never a behaviour of Test Event its a behaviour of ReportCard Object although it could be associated with Test Class like the ReportCard Class must be calling some TestClass Method to communicate.

Chapter class have behaviours such as getChapterID(), getChapterName(), getTopics(), modifyTopics(), addNewTopic(), getReferences() etc But will getChapterTest() really be a behavior of Chapter or seems more proper to be a behaviour of Test

simply thinking what are the activities associated with the Chapter specifically the chapter only..we can read it, we can write a chapter, we can modify, we can bookmark a chapter, but if i say i am giving a test of the chapter can we really call it a part of chapters behaviour. I am really confused...simply saying that chapter has tests doesnt make a full proof real world model...LETS DISCUSS THIS
 
shukla raghav
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please if anyone can reply for the Question...
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PatienceIsAVirtue.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!