Results 1 to 2 of 2

Thread: strategy pattern implementation

  1. #1
    Sencha User
    Join Date
    Mar 2012
    Posts
    24

    Default strategy pattern implementation

    i would like to implement strategy patter but i have no idea how to do this.
    Let there is one class(controller for example) and there are dozes of conditional flow "if(some field of model) <do this> else if <do this>" and so on. So i have extracted all such flows in separated methods and now i am stuck. what i need it is to make some conditional mixing — so i could be able to move all methods in different mixins and apply them in init. But mixins are applied unconditionally(almost statically — at the moment of class' definition). So as for now i have only variant with Ext.Object.apply(this, new <more suitable mixin>) but as for me it looks ugly.
    Is there some other approach?

  2. #2
    Sencha User
    Join Date
    Mar 2012
    Posts
    24

    Default

    it has been implemented with Ext.apply and it looks like this:
    Code:
        applyMixins: function() {        
            var toApply = {};
            Ext.apply(toApply, new MainViewMixins.DefaultMixin());
            if (<some condition>) {
                Ext.apply(toApply, new MainViewMixins.SomeConditionMixin());
            }
            if(<some condition 2>) {
                Ext.apply(toApply, new MainViewMixins.SomeMixinIf());
            } else {
                Ext.apply(toApply, new MainViewMixins.SomeMixinElse());
            }
            Ext.applyIf(this, toApply);
        }
    that is executed while initComponent is invoking
    apply and additional object are used because there are same-named methods in different mixins. And applyIf is used to avoid applying such properties like $base and super.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •