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?
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
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.
@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