Design pattern for designers

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;
            // Do some stuff with ingredients of styleSheet
        }
    }
    class StyleSheetA
    {
        int n1;
        int n2;
        // :
        // :
        int n100;
    }

    class B extends A
    {
        B(StyleSheetB ss)
        {
            super(ss);
            // Do some stuff with ingredients of styleSheet
        }
    }
    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.

+5
source share
3

, A StyleSheetA.

, : StyleSheetA? , , , . , , - , StyleSheetA, A. , , , A, , .

, , - A. . nesseccary, , ..

, A, , , , , . - ( , "type" ), , , .

+5

IoC, StructureMap, ? .

+3

:

'B' , (n101 +) . , n101... n200 B n1... n100 A. , , , StylesheetB extend StylesheetA, B B(StyleSheetA,StyleSheetB), , A , B StylesheetB.

+2

All Articles