MVC (Model-View-Controller) implementation in VB.NET
I am wondering what I am missing in the attached code that is making it impossible for me to make the VB.NET program below work using MVC (Model-View-Controller).
Right now, I am really lost despite my best efforts...
I am trying to implement the observer pattern and think that my code is getting closer to MVC but not quite there yet, firstly because it wont even run ... nevertheless I know that there is someone out there who knows what I am doing wrong
and I would definitely benefit from any guidance or help that someone more experienced in MVC VB.NET implementation can
give .. hence this letter.
So far Im really stumped and would forever be grateful for any help you could give.
Gratefully,
Matt
P.S.
I think the original post did not make it as when I try to search using the name of the one who posted the thread I dont get any result returned .... in that post I experimented using attachment ... looks like there is a problem with using attachment so I am redoing the posting here and this time not using any attachment and instead I have copy pasted all the source code here as shown below ... thanks
Code:
'''first interface the subject interface
Interface Isubject
Sub registerobserver(Iobserver o)
sub removeobserver(Iobserver o)
Sub notifyobservers()
End Interface
'''second interface the observer interface
Interface Iobserver
Sub update()
End Interface
'''1st class
Imports Autodesk.AutoCAD.Interop
Imports AutocadMAP
Imports Scripting
Public Class AutoCADaccess
Private ThisDrawing As AcadDocument
Private DrawingName As String
Public Sub AutoCADaccess() implements Isubject
Iobserver = New ArrayList
End Sub
public sub registerObserver(Iobserver o)
Iobserver.add(o)
End Sub
Public Function connectDrawing() As AcadDocument
Dim AcadApp As AcadApplication
Dim DrawingTitle As String
If ThisDrawing Is Nothing Then
On Error Resume Next
Err.Clear()
AcadApp = GetObject(, "AutoCAD.Application")
If Err.Number Then 'need to create object
AcadApp = CreateObject("AutoCAD.Application")
End If
AcadApp.Visible = True
ThisDrawing = AcadApp.ActiveDocument
AcadApp.WindowState = Common.AcWindowState.acMax
ThisDrawing.WindowState = Common.AcWindowState.acMax
End If
connectDrawing = ThisDrawing
End Function
Public Function setDrawingTitle() As String
Dim ObtainedTitle As String
ObtainedTitle = ThisDrawing.GetVariable("dwgname")
Me.DrawingName = "Title Block [" & ObtainedTitle & "]"
End Function
End Class
'''2nd class
Imports Autodesk.AutoCAD.Interop
Imports AutocadMAP
Imports Scripting
Public Class AutoCADtitle
Public Shared Sub main()
Static ThisDrawing As AcadDocument
Dim acad As New AutoCADaccess
Dim AcadMap As AcadMap
With acad
ThisDrawing = .connectDrawing
End With
MsgBox("Title Block [" & ThisDrawing.GetVariable("dwgname") & "]")
End Sub
End Class
'''the form which I am trying to have absorb in its caption the drawing name of the current drawing
Option Explicit On
Imports Autodesk.AutoCAD.Interop
Imports AutocadMAP
Imports Scripting
Public Class frmTitleBlk
Inherits System.Windows.Forms.Form
end Class
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''' THE GOAL, IE.. THAT OF GRABBING THE NAME OF THE '
'''' CURRENT DRAWING AND PUTTING IT IN THE CAPTION OF '
'''' THE LOADED FORM (frmTitle) IS EASY TO IMPLEMENT IF ONLY WE'
'''' ARE NOT DICTATED TO USE MVC ... IN THE LONG RUN '
'''' I GUESS MVC ARCHITECTURE IS GOOD SO I AM TRYING '
'''' TO BUILD THE THING USING IT ... ANYHOW, THE WAY '
'''' I ORIGINALLY WROTE THE PROGRAM IS SHOWN BELOW WHICH '
'''' I HAVE MODIFIED TO THAT WHICH IS SHOWN ABOVE '
'''' IE..THE ABOVE IS MOVING TOWARDS MVC .. BUT IN THE '
'''' ABOVE I AM NOT EVEN SURE IF I CAN DO frmTitleBlk.show from'
'''' from the sub called main without breaking MVC rules '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Imports Autodesk.AutoCAD.Interop
Imports AutocadMAP
Imports Scripting
Public Class AutoCADaccess
Private ThisDrawing As AcadDocument
Public Function connectDrawing() As AcadDocument
Dim AcadApp As AcadApplication
If ThisDrawing Is Nothing Then
On Error Resume Next
Err.Clear()
AcadApp = GetObject(, "AutoCAD.Application")
If Err.Number Then 'need to create object
AcadApp = CreateObject("AutoCAD.Application")
End If
AcadApp.Visible = True
ThisDrawing = AcadApp.ActiveDocument
AcadApp.WindowState = Common.AcWindowState.acMax
ThisDrawing.WindowState = Common.AcWindowState.acMax
End If
connectDrawing = ThisDrawing
End Function
End Class
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit On
Imports Autodesk.AutoCAD.Interop
Imports AutocadMAP
Imports Scripting
Public Class frmTitleBlk
Inherits System.Windows.Forms.Form
Private Sub TitleBlk_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ThisDrawing As AcadDocument
Dim acad As New AutoCADaccess
Dim AcadMap As AcadMap
With acad
ThisDrawing = .connectDrawing
End With
Me.Text = "Title Block [" & ThisDrawing.GetVariable("dwgname") & "]"
End Sub
End Class
Last edited by Shuja Ali; April 27th, 2009 at 02:20 AM.
Reason: Added code tags
Re: MVC (Model-View-Controller) implementation in VB.NET
Matt, I had this link bookmarked long time back. May be you should go through this once and see how it is done in the example that he has shown. Al though it is little old, but I guess you can still use it http://www.devx.com/dotnet/Article/10186
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.