Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7070921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:37:29+00:00 2026-05-28T05:37:29+00:00

(Using Python 3.2, though I doubt it matters.) I have class Data , class

  • 0

(Using Python 3.2, though I doubt it matters.)

I have class Data, class Rules, and class Result. I use lowercase to denote an instance of the class.

A rules object contains rules that, if applied to a data object, can create a result object.

I’m deciding where to put the (rather complicated and evolving) code that actually applies the rules to the data. I can see two choices:

  1. Put that code inside a class Result method, say parse_rules. Result constructor would take as an argument a rules object, and pass it onto self.parse_rules.

  2. Put that code inside a new class ResultFactory. ResultFactory would be a singleton class, which has a method, say build_result, which takes rules as an argument and returns a newly built result object.

What are the pros and cons of the two approaches?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:37:30+00:00Added an answer on May 28, 2026 at 5:37 am

    The GRASP design principles provide guidelines for assigning responsibility to classes and objects in object-oriented design. For example, the Creator pattern suggests: In general, a class B should be responsible for creating instances of class A if one, or preferably more, of the following apply:

    • Instances of B contains or compositely aggregates instances of A
    • Instances of B record instances of A
    • Instances of B closely use instances of A
    • Instances of B have the initializing information for instances of A and pass it on creation.

    In your example, you have complicated and evolving code for applying rules to data. That suggests the use of the Factory Pattern.

    Putting the code in Results is contraindicated because 1) results don’t create results, and 2) results aren’t the information expert (i.e. they don’t have most of the knowledge that is needed).

    In short, the ResultFactory seems like a reasonable place to concentrate the knowledge of how to apply rules to data to generate results. If you were to try to push all of this logic into class constructors for either Results or Rules, it would lead to tight coupling and loss of cohesion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(The following is using Python 2.6.1) I have 2 strings: >>> a = u'\u05e8\u05db\u05e1'
I'm looking for information on how to read GnuCash files using python. I have
I'm using Python 2.6, and I have two datasets, each being a list of
working on creating an XML file with some data using Python. I am trying
I am using python 2.6 on XP. I have just installed py2exe, and I
I want to take a screenshot using python. I have tried using PIL, but
I'm a grader for a beginning programming class using Python. My python-fu is not
I have a Python program that sends keystrokes to another application using SendKeys. Some
Using SQLite3 with Python 2.5, I'm trying to iterate through a list and pull
I'm trying to submit a few forms through a Python script, I'm using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.