maonet technotes

IOC(SM):MOC(RM):TDD(NU):SCC(TFS):ORM(L2S):JSL(Jq):CIS(CC)

Apply MVP pattern in PowerBuilder Application

Posted by Frank Mao on February 21, 2008

Lack of interface, it is very hard to implement MVP design pattern in PB application, so I created a variation like this:

pb_mvp.gif

All the objects expect UI are non-visual objects. ViewBinded is inherited from view object. UI will be tightly coupled with viewbinded nvo, (they are acting more like a partial class in dotNet word) but UI doesn’t couple with either of view or presenter, so unit-test presenter becomes possible.

A code demo will look like this:

/*w_demo.open event */
inv_view = create n_cst_viewbinded_demo
inv_view.of_init(this)

/* viewbinded. of_init(aw_ui) */
inv_presenter = create n_cst_presenter_demo
f_init( aw_ui, inv_presenter )

/* viewbinded.of_init(aw_ui, anv_presenter) */
iw_ui = aw_ui
inv_presenter = anv_presenter
inv_presenter.inv_view = this
inv_presenter.of_some_action( )

/* presenter.of_some_action() */
inv_model.of_call_base_on_view_properties(inv_view.Property1)
//…process…
inv_view.event ue_after_process()

/* viewbinded.event ue_after_process */
aw_ui.st_statuts.text = “Jon finished.”

I tried to unit-test pb app by setting up some fake UI, like lw_1 = create w_1, like I found out before, PB won’t complain but the open and close event won’t be triggered. Today I found another bad thing, this fake action can also cause a unable-reload problem in my handy unit-test tool, PowerUnit/PBUnit. Once I remove those fake creation of UI object in my unit-test code, this problem won’t away.

One Response to “Apply MVP pattern in PowerBuilder Application”

  1. [...] had to adopt MVP pattern (kind of, becuase PB doesn’t support interface) to my userobject/window to make unit-test possible. The new term of MVP, Passive View, makes more sense for pattern [...]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>