Tuesday, 19 April 2016

Facade pattern - Example


interface General {
    public void accessGeneral();
}

interface Special extends General {
    public void accessSpecial();
}

interface Private extends General {
    public void accessPrivate();
}

class GeneralInfo implements General {
    public void accessGeneral() {
    //...
    }
    //...
}

class SpecialInfo implements Special{
    public void accessSpecial() {
        //...
    }
    public void accessGeneral() {}
      //...
}

class PrivateInfo implements Private, Special {
    public void accessPrivate() {
    // ...
    }
    public void accessSpecial() {
    //...
    }
    public void accessGeneral() {
    // ...
    }
    //...
}

class Connection {
   //...
   if (user is unauthorized) throw new Exception();
   if (user is general) return new GeneralInfo();
   if (user is special) return new SpecialInfo();
   if (user is executive) return new PrivateInfo();
   //...
}

The above code example illustrates that the whole system is not exposed to the clients. It depends on the user classification.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.