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.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail


In reply to Re: OO - Where to put a method by BrowserUk
in thread OO - Where to put a method by Jaap

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.