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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:41:10+00:00 2026-05-29T06:41:10+00:00

In one app, I have a task to create files that will be used

  • 0

In one app, I have a task to create files that will be used by a third party. Actually there are three distinct types of content in the files:

  1. List of employee cards to send data to the third party app;
  2. List of employee cards to collect biometry;
  3. Interval of numbers.

For now I have just one class called FileGenerator (generic, bad name I think) that receives the data and creates a file with some name convention (code of clock, type of file, date and hour).

There’s a good design pattern to ensure that the file name convention will remains and to split the generation of files in specific classes for each type of file?

There’s a good way to reuse the code that generates the file (don’t repeating myself in the specific classes)?

This is part of the existing class:

class FileGenerator {
    private List<String> contentOfFile;
    private String fileName;

    //I - include employees
    //C - change employees
    //R - remove employees
    //B - collect biometry
    //N - interval of numbers
    private String option;

    private void getFileName(){ ... } //this assure the file name convention
    public void generate(){ ... } //this generate the file with content

}

What I think so far:

  1. Create one abstract class to hold the name convention. And to write the content to a file.
  2. Create a factory class that will know all the types of files (factory is a good pattern to use here?).
  3. Implement concrete classes to the types of files to define which content will be written.
  • 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-29T06:41:11+00:00Added an answer on May 29, 2026 at 6:41 am

    More or less what you said:

    1-The template method pattern for writing the file. I am thinking something like this:

    public abstract class EmployeeCardFileGenerator {
       /**
       * @return the generated file name
       */
       public abstract String getFileName(/*any params you need to get the file name*/);
    
       /**
       * @return the line corresponding to the given data record
       */
       public abstract String getLine(EmployeeCardData data);
    
       /**
       * @return the header to be appended at the beginning of the file
       */      
       public abstract String getHeader(/*any header params*/);
    
       /**
       * @return the footer to be appended at the end of the file
       */
       public abstract String getFooter(/*any footer params*/);
    
       public void generateFile(/*any params*/) {
          List<EmployeeCardData> data = queryData();
    
          File f = createFile();
          PrintWriter pw = getWriter(f);
          pw.println(getHeader());
    
          for(EmployeeCardData ec : data) {
              pw.println(getLine(ec));
          }
    
          pw.println(getFooter());
    
          cleanup();
       }
    }
    

    2- You would have different implementations of these, dispensed by a factory.

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

Sidebar

Related Questions

Is it possible to have two app.config files where one app.config serves as a
I have one console app that is doing some lengthy syncing to an ftp
Story: One of the app that i have works on python 2.4 and other
I am creating a rails app and have used this code in one of
I have VPS with 1GB of RAM. One ruby-app that runs on thin server
We have an app that uses simple one way binding with a GridView to
I have a Scripts folder, that includes all the .js files used in the
In my app I have a background task (using AsyncTask) that downloads stuff from
My task is create both login and registration form on one view! I have
I have a rake task that populates some initial data in my rails app.

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.