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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:27:58+00:00 2026-05-30T23:27:58+00:00

I am creating a certain class using MyClass class1 = new MyClass(ClassA.StaticSet1, ClassA.StaticCoef1); MyClass

  • 0

I am creating a certain class using

MyClass class1 = new MyClass(ClassA.StaticSet1, ClassA.StaticCoef1);
MyClass class2 = new MyClass(ClassB.StaticSet1, ClassB.StaticCoef1);

so I wanted to gather all these static values in one class and call them using something like

MyClass class1 = new MyClass(TopClass.Obj1);
MyClass class2 = new MyClass(TopClass.Obj2);

where Obj1 and Obj2 are static entities containing the abovementioned pairs of values.

the closest thing I could do was creating static classes inside TopClass and extending one base class
so I got this ugly implementation

Public class TopClass{
    public static class Base{
        public String set[];
        public double coef[];
        public Base(s, c){
            set = s;
            coef = c;
        }

    }
    public static class Obj1 extends Base{
        public static String set[] = {"a","b","C"};
        public static double coef[]= {1,2,3};
        public Obj1(){
            super(set, coef);
        }

    }
    public static class Obj2 extends Base{
        public static String set[] = {"x","y","z"};
        public static double coef[]= {11,12,13};
        public Obj2(){
            super(set, coef);
        }


    }

}

then I call them with

Myclass class1 = new MyClass((TopClass.Base)(new TopClass.Obj1());
Myclass class2 = new MyClass((TopClass.Base)(new TopClass.Obj2());

but this wasn’t what I exactly wanted because the class became cumbersome especially that I will be creating many of these entries.
any insight would be much appreciated 🙂

thanks,

Hani

  • 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-30T23:27:59+00:00Added an answer on May 30, 2026 at 11:27 pm

    This would be a great place to use a Factory pattern. Maybe something like:

    public class SetCoefProvider {
      private String[] set;
      private double[] coef;
    
      public SetCoefProvider(String[] set, double[] coef) {
        this.set  = set;
        this.coef = coef;
      }
    
      public String[] getSet() {
        return set;
      }
      public double[] getCoef() {
        return coef;
      }
    }
    
    public class SetCoefProviderFactory {
      public static SetCoefProvider createObj1Provider() {
        return new SetCoefProvider(new String[] {"a", "b", "c"}, new double[] {1,2,3});
      }
      public static SetCoefProvider createObj2Provider() {
        return new SetCoefProvider(new String[] {"x", "y", "z"}, new double[] {11,12,13});
      }
    }
    

    and then if you really want them to be singletons, you can always do something like:

    public class SingletonSetCoefProviders {
      private static SetCoefProvider obj1Provider, obj2Provider;
    
      static {
        obj1Provider = SetCoefProviderFactory.createObj1Provider();
        obj2Provider = SetCoefProviderFactory.createObj2Provider();
      }
    
      public static SetCoefProvider getObj1Provider() {
        return obj1Provider;
      }
      public static SetCoefProvider getObj2Provider() {
        return obj2Provider;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a program that displays a popup at certain times (just like
I'm trying to get a certain cookie in a java client by creating a
I am creating Windows service class in Python that will eventually display a Window
I am creating a page that allows users access to a certain section of
I am creating a SOAP service using JAX-WS and JAXB, by annotating the classes.
I'm creating a user approval interface leveraging the .Net Membership class. I have a
I have a class library with all my database logic. My DAL/BLL. I have
I need to check whether a certain class extends or implements a particular interface.
I am trying to create a window with a certain class type (VSDebugger CDataTipWnd),
I'm using CI's Auth Tank library to query records for certain users. The variable

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.