can Chain of Responsibility have a predessesor or there should be only successor in chain. I mean that if we need to call previous objects in chain. Is it possible. As much as I have seen online there are only successor. Will setting up a predessesor break the chain. For example,
Handler object1 = new Start(); // return index of "c" in target String
Handler object2 = new Normal();// matches "a"
Handler object3 = new Dot(); // matches any one character
Handler object4 = new End(); // matches "t",i.e., end of chain
object1.setSuccessor(object2);
object2.setSuccessor(object3);
object3.setSuccessor(object4);
Match match = new Match( "car.ot" );
object1.find( match );
Actual problem is how to match "r" and "o" using given chain of objects.
Here I need to match given String. object1 will return the position of "c". object2 will match "a". If its true , it should pass to match "r" to the next object in chain. How to do it without using a predessesor. Please help.
Aucun commentaire:
Enregistrer un commentaire