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

  • Home
  • SEARCH
  • 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 6335381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:50:49+00:00 2026-05-24T18:50:49+00:00

(note) I would appreciate help generalizing the title. I am sure that this is

  • 0

(note) I would appreciate help generalizing the title. I am sure that this is a class of problems in OO land, and probably has a reasonable pattern, I just don’t know a better way to describe it.

I’m considering the following — Our server script will be called by an outside program, and have a bunch of text dumped at it, (usually XML).

There are multiple possible types of data we could be getting, and multiple versions of the data representation we could be getting, e.g. “Report Type A, version 1.2” vs. “Report Type A, version 2.0”

We will generally want to do the same thing action with all the data — namely, determine what sort and version it is, then parse it with a custom parser, then call a synchronize-to-database function on it.

We will definitely be adding types and versions as time goes on.

So, what’s a good design pattern here? I can come up with two, both seem like they may have som problems.

Option 1

  • Write a monolithic ID script which determines the type, and then
    imports and calls the properly named class functions.
  • Benefits

    • Probably pretty easy to debug,
    • Only one file that does the parsing.
  • Downsides

    • Seems hack-ish.
    • It would be nice to not have to create
      knowledge of dataformats in two places, once for ID, once for actual
      merging.

Option 2

  • Write an “ID” function for each class; returns Yes / No / Maybe when given identifying text.
  • the ID script now imports a bunch of classes, instantiates them on the text and asks if the text and class type match.
  • Upsides:
    • Cleaner in that everything lives in one module?
  • Downsides:
    • Slower? Depends on logic of running through the classes.

Put abstractly, should Python instantiate a bunch of Classes, and consume an ID function, or should Python instantiate one (or many) ID classes which have a paired item class, or some other way?

  • 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-24T18:50:50+00:00Added an answer on May 24, 2026 at 6:50 pm

    You could use the Strategy pattern which would allow you to separate the logic for the different formats which need to be parsed into concrete strategies. Your code would typically parse a portion of the file in the interface and then decide on a concrete strategy.

    The structure of the strategy pattern.

    As far as defining the grammar for your files I would find a fast way to identify the file without implementing the full definition, perhaps a header or other unique feature at the beginning of the document. Then once you know how to handle the file you can pick the best concrete strategy for that file handling the parsing and writes to the database.

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

Sidebar

Related Questions

Would appreciate if somebody could help me with something like this: NOTE!: I Do
I would appreciate your help on this: I have 2 models: class Author <
How would you do this PHP switch statement? Also note that these are much
I would appreciate if somebody could help me with this (and explaining what's going
This is really confusing me, I would appreciate if anyone could help me out.
I would like to set values on an url like this: <a href='http://$data_url/viewyournote.php?chapter='$name_of_chapter'&note='$id_note'&user='$username'> Then
I needed some help/pointers on a homework problem. I would really appreciate it if
I'm new to regular expressions and would appreciate your help. I'm trying to put
Note - I will really appreciate a quick and complete answer to this question.
I'd like to note first that this is an education attempt on my own

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.