I would like to take advantage of this thread to make sure that's correct a design that I implemented:
Let's say that for BehaviorOneImpl I have two other behaviors and two other concrete classes to access those behaviors. So,
I applied the Strategy pattern once again for BehaviorOneImpl and I have the following:
Code:
//Previous implementation "First Level Behavior"---------------------
...
//Interface Implementation
class BehaviorOneImpl implements BehaviorOne{
void credit () {
System.out.println("do something");
}
..
//------------------------------------------
//classes
class BehaviorOneImplClassOne extends BehaviorOneImpl {
...
}
class BehaviorOneImplClassTwo extends BehaviorOneImpl {
...
}
//interfaces
interface BehaviorOneImplClassOneInterface {
...
}
interface BehaviorOneImplClassTwoInterface {
...
}
//Implementations concrete class "Second Level Behavior"
class SecondLevelBehaviorClassOne implements BehaviorOneImplClassOneInterface {
...
}
class SecondLevelBehaviorClassTwo implements BehaviorOneImplClassTwoInterface {
...
}
//Since SecondLevelBehaviorClassOne has many subclasses, I created an interface and in this way it's possible to access the interface
//instead using extends (concrete classes).
interface ISecondLevelBehaviorClassOneInterface {
public SecondLevelBehaviorClassOne getInformation(SecondLevelBehaviorClassOne secondLevelBehaviorClassOne);
}
//And finally, the implementation of the different classes. As you can see, the goal here is the WhateverItIsOne access the interface
//ISecondLevelBehaviorClassOneInterface instead access the class SecondLevelBehaviorClassOne directly.
class WhateverItIsOne implements ISecondLevelBehaviorClassOneInterface{
public SecondLevelBehaviorClassOne getInformation(SecondLevelBehaviorClassOne secondLevelBehaviorClassOne) {
....
}
}
class WhateverItIsTwo implements ISecondLevelBehaviorClassOneInterface{
public SecondLevelBehaviorClassOne getInformation(SecondLevelBehaviorClassOne secondLevelBehaviorClassOne) {
....
}
}
class WhateverItIsThree implements ISecondLevelBehaviorClassOneInterface{
public SecondLevelBehaviorClassOne getInformation(SecondLevelBehaviorClassOne secondLevelBehaviorClassOne) {
....
}
}
//And the same for the BehaviorOneImplClassTwoInterface.
Note that my class BehaviorOneImpl represents the very same "position" as the class A in the above example.
I don't want you to do my job, but if you have a better idea or agree that it's ok, would be great.
Regards.