Ir al contenido principal

Entradas

Mostrando entradas de julio, 2017

Design Patterns in Java (Behavioral) - Command Pattern

Command Pattern Encapsulate request as an object Object-oriented callback Decouple sender from processor Often used for "undo" action Design Object per command Command interface execute method undo method Use reflexion Main public static void main(String[] args ) { //Receiver - (Action) LightReceiver lc = new LightReceiver(); //OnCommand = concrete command Command c = new OnCommand( lc ); //Invoker - (Execute) SwitchInvoker si = new SwitchInvoker(); si .storeAndExecute( c ); } Receiver public class LightReceiver { public void on(){ System. out .println( "Light is on" ); } public void off(){ System. out .println( "Light is off" ); } } Invoker public class SwitchInvoker { public void storeAndExecute( Command command ){ command .execute(); } } Command public interface Command {...

Design Patterns in Java (Behavioral) - Chain of Responsability

Chain of  Responsibility Decoupling sender from receiver Promote loose coupling Example This example pass a request to be approved and validate if that position can approve it or need to be passed to the next level. Main public static void main(String[] args ) { Manager m = new Manager(); Director d = new Director(); CEO c = new CEO(); m .setSuccesor( d ); d .setSuccesor( c ); Request r1 = new Request(1, 500); m .handleRequest( r1 ); Request r2 = new Request(2, 500); m .handleRequest( r2 ); } Handle public   abstract   class   Handler { protected   Handler   succesor ; public   void   setSuccesor(Handler   succesor ){ this . succesor   =   succesor ; } public   abstract   void   handleRequest(Request   r ); } Request publi...

AngularJS: Directive

Directive Register directive with reserved word "directive" Simple Directive app.directive( 'myDirective' , function ($compile) { return { restrict: 'E' , link : function (scope, element, attrs, controller) { var markup = "<input type='text' ng-model='test' /> {{test}} <br/>" ; angular.element(element).html(markup); $compile(element.contents())(scope); } }; }); Include Directive  To add the directive Angular is Camel sensitive In the html include the directive in a tag HTML < my-directive /> Include Directive  The elements for a directive can be: E - element A- attribute C-class M - comments app.directive( 'myDirective' , function ($compile) { return { restrict: 'E' , template: "<input type='text' ng-model='test' /> {{test}} <br/>" ...