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 7904061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:54:04+00:00 2026-06-03T09:54:04+00:00

I am making a program that takes input from files that I have called

  • 0

I am making a program that takes input from files that I have called scripts. A script simply contains a series of information. In the future, I will need each script to contain more information, so I am associating each script with a version number.

The information in any script file can be completely contained into a particular class called EntityStatePdu (the details of which are not important for this question). So, I decided to make the following classes:

1) abstract class Script
2) class ScriptV1 extends Script
3) class ScriptV2 extends Script
4) …

I made each script file start with its version info. So, Version 1 scripts start with “scriptV1” and Version 2 scripts start with “scriptV2”. I would like to abstract the different script versions into the script class.

So, ideally, I want to have a factory method in the Script class called FromFile, such that calling Script.FromFile("scriptVersion1.txt") returns a valid ScriptV1 object and calling Script.FromFile("scriptVersion2.txt") returns a valid ScriptV1 object. I want the FromFile method to read the file, determine it’s version by looking at what the file starts with, and instantiate the appropriate Script subclass. This would let the user of the class use any script file, independent of version.

How would you go about writing this FromFile factory method? Would you suggest a different class design? Some sort of design pattern?

thanks!

  • 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-06-03T09:54:05+00:00Added an answer on June 3, 2026 at 9:54 am

    Add a static variable to the Script class to contain a map from strings (eg. “scriptV1”) to instances of the appropriate classes. In the FromFile method, extract the string, look it up in the map, clone the instance and return it. As an initialization stage, the subclasses need to register an instance of themselves in the map under the appropriate string.

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

Sidebar

Related Questions

i have a program that takes some time creating pdf files i would like
I'm making a program that takes names from the user seperated by commas. The
Im making an application that uses of API-threads in C, The program takes N-files
I'm making a Java program that takes some text as input, and has to
I'm currently making a PHP-program that solves equations. I've divided the input equation into
Im making a program for class that manages a Hotel. I have a function
I'm making a program that connects to a website and downloads XML from it.
I have a program ( grabface ) that takes a picture of the face
I am making a basic program which takes some input and prints it back
I'm making this function that takes a string input, converts it to an int,

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.