[Tutor] Structure of my simulation / monte-carlo

Kent Johnson kent37 at tds.net
Sun Nov 1 16:58:49 CET 2009


On Sun, Nov 1, 2009 at 10:47 AM, Vincent Davis <vincent at vincentdavis.net> wrote:
> Kent Johsnon writes
> "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."
> I am trying to do what you recomend, as much as makes sense to me, but that
> is why I ask the question so I should consider your answer.
> This is what I hear you saying, (I don't mean to represent them as
> sub-classes but more how they would operate on each other) Should I consider
> making Institutions) a subclass of (Make Institutions)? I can't think of
> anything that would make sense to inherit.
> class Simulation:
>     class Create Institutions:
>         class Institutions:
>     class create Applicants:
>         class Applicants:
>     class Match:
>     class Multi Match:
> I add I am thinking
> class Simulation:
>     def__init__:(self, results, stats.....repeat..)
>     def create_applicants():
>         class Applicants
>     def creat_institutions():
>         class Institutions
>     def one_simulation(): # one or more
>         create_applicants()
>         create_institutions()
>         class Match()
>         class Results
>     def repeat_simulation()
>         repeat one_simulations
>         class Results
> After writing this out I now think you are right, more classes.

Now you are getting too complicated. You don't need to use inheritance
or nested classes, and you can use simple methods (not classes) to
create applicants and institutions. You already have Applicant,
Institution and Match classes that run a single match. Now make a
RepeatMatch class that uses the Match class to run multiple
simulations.

Kent


More information about the Tutor mailing list