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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:35:36+00:00 2026-06-16T04:35:36+00:00

hi all: I am working on two java programs where literally the only difference

  • 0

hi all: I am working on two java programs where literally the only difference between the two are a beginning statement defining a 2-dimensional array. i have shortened the code substantially in the below example:

public class Qwerty {
    /** this is what needs to be replaced */
    private static char master[][] = {
        QwertyKbd.lIndex,
        QwertyKbd.lMiddle,
        QwertyKbd.lRing,
        QwertyKbd.lPinky,
            /** and so forth in this fashion */
    };

    public static int[] analyze(String file) {
    }

    public static void split(char c) {
    }
}

and the second class here:

 public class Dvorak{
        /** this is what needs to be replaced */
        private static char master[][] = {
            /** various definitions, eliminated for conciseness */
        };

        public static int[] analyze(String file) {
            /** this is the same*/
        }

        public static void split(char c) {
            /** this is the same*/
        }
    }

the question is how can i refactor to get one class where the only difference is the ‘master’ 2-d array? hook methods etc. would be stupid here. because there’s nothing that the program DOES that needs to be modified. what do you think?

  • 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-16T04:35:37+00:00Added an answer on June 16, 2026 at 4:35 am

    You couldn’t do that if your classes are in diffent projects
    But if they are parts of an project, you could create an abstract class, or superclass for all of your classes: Qwerty, Dvorak…
    For example, you create an abstract

    public class CustomAbstract{
        protected char master[][];
        public int[] analyze(String file){return null;};
        public void split(char c){};
    }
    

    Then in your classes, you extends this abstract class

    public class Qwerty extends CustomAbstract{
        public Qwerty(){
            //master = ...;
        }
        //your code
    }
    

    When you refactor the master field in CustomAbstract, all of master in other classes are refactored, too.

    The problem of above code is that you couldnt use static field master, eventhough static method analyze, etc. May be you need all of methods and fields in your classes are static, you could use single skeleton pattern. In each class, you create a static method like that

    public class Qwerty extends CustomAbstract{
        //your code
        static Qwerty instance = new Qwerty();
        public static Qwerty getInstance(){
            return instance;
        }
    }
    

    Then instead of using Qwerty.analyze(String), you can use Qwerty.getInstance().analyze(String)
    Hope this help.

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

Sidebar

Related Questions

We have three developers and one tester all working against the same database. We
I have a draggable table which all working fine, though I want to be
I'm working through the NerdDinner ASP.NET MVC 1.0 example. I have it all working
i have a dynamic php web page localhost/ctd/index.php All working good except if i
I'm fairly new to programming in general but have been working with Java for
Im working in a Web App with Java and JSF. I have a simple
I have two of the following java classes (listed below) Class BookInfo declares static
So I have been working on a 2 player Tic-Tac-Toe game in java that
I am working on a java project and need to print common values between
I have two Eclipse Maven Java projects. A domain project that is laden with

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.