开发者

code reuse with event based programming in extjs4 mvc

开发者 https://www.devze.com 2023-04-03 18:21 出处:网络
I have a wizard with each step a form.On click of next wizard calls form.validate() and then switches to the ne开发者_如何学Pythonxt card. Validate does all sorts of business validation + basic form v

I have a wizard with each step a form. On click of next wizard calls form.validate() and then switches to the ne开发者_如何学Pythonxt card. Validate does all sorts of business validation + basic form validation.

I have an abstract superclass for all the forms that just does this.getForm().isValid() and the subclasses can override this to put their specific logic. Downside to this in extjs4 is u still have to implement this in ur view classes thus the mvc separation is not upheld.

Now what if in extjs4 we changed the validate from being a method to an event ?, for which all subclasses should define a handler and the wizard class on click of next just fires that event ?

This serves 2 purposes :

  1. it will make the call asynchronous
  2. u can implement ur business logic within controller classes.

The downside here is there is no way of providing a default implementation that can be shared like a default implementation in base class. Even if you have the base class implement a default handler for that event the downside to that model is unlike inheritance based sharing u can't decide to turn off that behavior by not calling this.callParent(arguments).

So the missing piece here is how is it possible to have a inheritance-like reuse possible in a event based paradigm ?

0

精彩评论

暂无评论...
验证码 换一张
取 消