Page 1 of 1

Controller design pattern

Posted: Tue Oct 19, 2010 3:46 am
by Mistrel
Because PureBasic lacks facilities such as OO, class inheritance, and procedural interfaces, this controller library is extremely simple. But it imitates the principles nonetheless. Part of its simplicity is due greatly in part due to the built in Map library.

This library is to assist with another library I'm working on that allows procedural calls to affect a web gadget via JavaScript but also vice versa where you can call procedures in your application from JavaScript events or "tokens", for when JavaScript is not acceptable or otherwise wouldn't be called.

For more information on what a controller is and how it is useful for web (and in my case, GUI) applications, see here:

http://en.wikipedia.org/wiki/Model%E2%8 ... Controller

Code: Select all

Prototype.i Controller_Prototype(Args.s, Delim.s)

Procedure Controller_Add(*Controller, Name.s)
  If Not *Controller Or Not Name.s
    ProcedureReturn #False
  EndIf
  
  Glob_Controller_Map(Name.s)=*Controller
  
  ProcedureReturn #True
EndProcedure

Procedure Controller_Exists(Name.s)
  If Not Name.s
    ProcedureReturn #False
  EndIf
  
  If Glob_Controller_Map(Name.s)
    ProcedureReturn #True
  EndIf
  
  ProcedureReturn #False
EndProcedure

Procedure Controller_Call(Name.s, Args.s="", Delim.s=",")
  Protected Controller.Controller_Prototype
  Protected Result
  
  If Not Name.s
    ProcedureReturn #False
  EndIf
  
  Controller=Glob_Controller_Map(Name.s)
  
  ProcedureReturn Controller(Args.s,Delim.s)
EndProcedure