Jump to content

Model View Controller -- advice


Recommended Posts

Hi, I've been reading up on MVC lately, so I decided to implement my own MVC according to my best understanding. Will you tell me how far short of the mark this code falls? Any other thoughts, ideas, etc will be appreciated too.

And yea, this is a simple toy example.

#AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -d

#include "AutoItObject.au3"
#include <GUIConstantsEX.au3>

HotKeySet("{ESC}", "_term")

Opt("GUIOnEventMode", 1)

_AutoItObject_Startup()

Global $Controller = Controller()

Global $Form = GUICreate("MVC Example", 200, 200)
Global $Label = GUICtrlCreateLabel("", 10, 10, 280, 25)
Global $Button = GUICtrlCreateButton("Click ME!", 100, 100)

GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUICtrlSetOnEvent($Button, "ClickButton")

GUISetState()

While 1
    Sleep(1000)
WEnd

Func Close()
    _term()
EndFunc ;==>Close

Func ClickButton()
    Return $Controller.Buttonclick($Label)
EndFunc ;==>ClickButton

_term()

Func _term()
    $Controller = 0
    _AutoItObject_Shutdown()
    Exit
EndFunc ;==>_term

#region Controller
Func Controller()
    Local $this = _AutoItObject_Create()
    _AutoItObject_AddProperty($this, "View", $ELSCOPE_PRIVATE, View())
    _AutoItObject_AddMethod($this, "Buttonclick", "_Controller_Buttonclick")
    Return $this
EndFunc ;==>Controller

Func _Controller_Buttonclick($this, $ctrl)
    Return $this.View.Buttonclick($ctrl)
EndFunc ;==>_Controller_Buttonclick
#endregion Controller



#region View
Func View()
    Local $this = _AutoItObject_Create()
    _AutoItObject_AddProperty($this, "Model", $ELSCOPE_PRIVATE, Model())
    _AutoItObject_AddMethod($this, "Buttonclick", "_View_Buttonclick")
    Return $this
EndFunc ;==>View

Func _View_Buttonclick($this, $ctrl)
    Local $data = $this.Model.SendData()
    Return GUICtrlSetData($ctrl, $data)
EndFunc ;==>_View_Buttonclick
#endregion View



#region Model
Func Model()
    Local $this = _AutoItObject_Create()
    _AutoItObject_AddProperty($this, "Data", $ELSCOPE_PRIVATE, "I'm a banana!")
    _AutoItObject_AddMethod($this, "SendData", "_SendData")
    Return $this
EndFunc ;==>Model

Func _SendData($this)
    Return $this.Data
EndFunc ;==>_SendData
#endregion Model
Edited by jaberwocky6669
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...