On Sat, Oct 31, 2009 at 12:54 PM, Vincent Davis <vinc...@vincentdavis.net> wrote:
> So my plan way to make a new class. This class would define the Applicant > characteristics "self.gpa = random.gauss(mean, SD)" and the > institutions self.quality = random.gauss(mean, sd) > so it would look something like this > > class RepeatMatch: > def __int__(self, app_mean, app_sd, inst_mean, inst_sd, match_ repeat) > self.app_mean = app_mean > …….. > self.match_repeat = match_repeat > def makeApplicants(): > def makeInstitutions(): > def runMatches(self) > # runs the match match_repeat number of times, saves results > # then I calculate some characteristics of the results > def ratio_dist(): > # returns the Mean and sd of GPA/Quality > END OF CODE > Does it make sense to do it this way? Is there a better/alternative way of > thinking about this. In the end I want to compare the results of repeated > simulations "RepeatMatch(50,2….) Compared to RepeatMatch(50,15….)" > This is way I had ask the earlier question "class attribute to initiate more > classes" This class has a lot of responsibilities: - create applicants - create institutions - run a single match - run multiple matches - calculate statistics on the result of multiple matches A principle of object-oriented design is that a class should have a single responsibility. I would break your class up a bit using multiple classes, perhaps MatchParameters - holds app_mean, etc Match - create applicants and institutions and run a single match, yielding a MatchResult MatchResult - the result of running a single match RepeatMatch - run multiple matches and accumulate results, yielding a RepeatResults RepeatResults - the result of running multiple matches - knows how to compute stats on itself You may think of better names, or a different way to organize it, but the idea is, don't shove everything into one class. Some of these may be just built-in data structures or very simple classes, such as MatchParameters which might be a dict or a collections.namedtuple. Kent _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor