I was questioned by the design problem, which I will try to describe below.
Suppose a class called A has a constructor with a set of parameters. Since it’s tedious and dirty to write all these parameters in each instance, I wrote another class, name it StyleSheetA, which encapsulates all these parameters and is the only parameter for constructor A. In this way, I can prepare some default values for StyleSheetA templates, which will be be used later, and if necessary, I can change them.
And at this point I need to extend A. Suppose B extends A. B will have its own stylesheet, namely StyleSheetB. I think it would be appropriate that StyleSheetB extends StyleSheetA, so with one style sheet parameter, constructor B can also build his superclass A. But I'm afraid this design may have flaws. For example, what if I decide to add getter / setter for the stylesheet? Is there a new way to handle all of these situations? Am I really wrong? For those embarrassed, I am attaching the code here:
class A
{
StyleSheetA ss;
A(StyleSheetA ss)
{
this.ss = ss;
}
}
class StyleSheetA
{
int n1;
int n2;
int n100;
}
class B extends A
{
B(StyleSheetB ss)
{
super(ss);
}
}
class StyleSheetB extends StyleSheetA
{
int n101;
int n102;
int n200;
}
Thank you for any help or suggestions, and any of your critics will be appreciated.
Edit: I develop in java to me, so there is no generic support.
source
share