This discussion is archived
1 Reply Latest reply: Nov 28, 2012 3:57 PM by jschellSomeoneStoleMyAlias RSS

cor design pattern

user11138293 Newbie
Currently Being Moderated
I use cor design pattern little different than what I see in google.

here is m y cor
     public static  abstract  class CORHandler    {
          CORHandler  nextHandler;
          public void process(){
               if(canHandleRequest()){
                    handleRequest();
               }else {
                    if(nextHandler!=null) nextHandler.process();
               }
          }
          protected abstract  boolean canHandleRequest();
          protected abstract void  handleRequest();
          public void setNextHandler(CORHandler  corHandler){
               nextHandler=corHandler;
          };
     }
this serves most of my need and also I can override process method for change behaviour .
this code helps me save lots of if/else conditions , I am not passing any object to the method here reason is I use this always as inner class inside a method so I can access all final fields
advice me is this right when applying cor pattern?
  • 1. Re: cor design pattern
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    Making it a base class increases connectivity to no good purpose.

    It violates the concept of inheritance by making the objects COR classes which is not what they are.

    It violates the principal of COR in that the intent is to handle a responsibility not all responsibilities. This same problem obscures the pattern as well by eliminating the objects to be acted upon.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points