Heavily influenced by (stealing large chunks of code from,) a colleague. I have decided to try my hand at implementing an MVC in lotus notes.
I've already had some success to. As you may imagine there a several issues around this, notes does not like to be used in clever ways and complains a lot.
My current design is based around a colleagues implementation of separation of code. In which he creates a class that is than bound to a form. This class allows you to separate all the many disparate bits of code from the form and create a single store of all that code. As you can imagine this makes finding/editing/fixing the code much easier, especially when combined with a rather nifty event/error logging code that i intend to "borrow". From this point on i will refer to this as the UI class.
So i took this model and defined the form as the View.
The UI class above is the controller.
The model is a new class i have added that performs the business logic and updates the "database"(document). It essential wraps the document for each form, and defines procedures around data retrieval/data setting/triggers etc. These functions are than used by the UI class. In this way i have decoupled the business logic from any UI specific commands.
By separating the Business logic into a separate class the document now follows the same processes when being created/deleted independent of weather it is done using the UI or through a background agent. Preventing the common problem of having to replicate code from the form (UI code) into agents when updating documents.
I'll give more specific examples in future posts, until then below is a very simple example. I'm doing this from memory so please forgive any mistakes.
public Class myFormUI
Private myForm as myForm
Private ws as NotesUiWorkspace
public sub new()
bindEvents()
set myForm = new MyForm()
.......
end Sub
private Function bindEvents()
.......
end Function
'use QuerySave to do preSave processing
private Function querySave()
call myForm.preSaveProcessing()
end Function
private Function onChangeOfName()
call myForm.onChangeOfName()
call ws.currentDocument().refresh()
messageBox("You changed the name field" & chr(10) & "Well done!")
end Function
end Class
public Class myForm
public sub new
end sub
public function preSaveProcessing()
........
end Function
public function setName(value as string)
.......
call onChangeOfName()
end function
public function onChangeOfName()
.......
end Function
end Class