in reply to OO - Where to put a method
That really depends upon what you mean by "AvergeScore"?
I could see the case for each of your existing classes having an GetAverageScore method.
Student::GetAverageScore() as an instance method gives the students average score for a given test or all tests. As a class method it might give the average score for all the students for a given test or for all tests to date.
Question::GetaverageScore() as an instance method gives the ave. score for the all answers to the individual question. As a class method it might give the ave. score for all questions.
Teacher::GetAverageScore() as an instance method gives the average score for all questions set by this teacher. Which might be contrasted with the response to a class method of the same name giving the average score for all questions set by all teachers therebye giving a measure of whether the individual teacher tends to set easy or hard questions.
A mechanism for deciding where a method fits is to decide where and how you want to use it. This is the basic idea behind the "Use cases" design methodology. From the context of when and where you want to use a piece of information, it is usually fairly obvious where the method that produces it belongs. It's not always clear cut, but it narrows the field in most cases.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: OO - Where to put a method
by Jaap (Curate) on Oct 08, 2003 at 07:16 UTC | |
by BrowserUk (Patriarch) on Oct 08, 2003 at 08:17 UTC |