java - Design pattern to handle settings in subclasses? -


I have a small hierarchy of classes that all implement a common interface.

Each concrete square needs to get only one setting structure, for example only the public sector The problem is that setting structure

  • one part is common for all classes
  • there is another part that varies from one concrete square to another

I think Was it that you had any elegant design in your mind to handle this. I would like to create something like this:

  BasFink = New Concrete Implementation 1 ();  

with Concrete implementation 1 implements the basefunction and

  doer.setSettings (settings)  

but There is a "Settings" object with a solid implementation that will be suitable for Concrete Implementation 1.

How would you do this?

This can be a designated design pattern, if it is, then I do not know the name. Announce an abstract class that implements the desired interface. An intangible class constructor should take an example of your settings object, which will remove the global setting. Obtain one or more squares from the abstract category The derived class constructor should take the example of its settings object, give it to the original category constructor, then remove any local settings.

Below is an example:

 class applies AbstractThing DesiredInterface {Private string global setting value 1; Private string global setting value 2; Protected AbstractThing (settings settings) {globalSettingValue1 = settings.getGlobalSettingsValue1 (); GlobalSettingValue2 = settings.getGlobalSettingsValue2 (); } Protected string getGlobalSettingValue1 () {Return global certificate value 1; } Protected string getGlobalSettingValue2 () {Return global certificate value 2; }} Category DerivedThing AbstractThing is extended {Private string is generated; Setting value value 1; Private string derivative valve 2; Public DerivedThing (settings settings) {super (settings); DerivedThingSettingValue1 = settings.getDerivedThingSettingsValue1 (); DerivedThingSettingValue2 = settings.getDerivedThingSettingsValue2 (); }} 

Comments