Interfaces to Different Layers RRS feed

  • Question

  • Hello,

    I am struggling to get the different layers of my project to communicate to each other and would be grateful for any advise. Here is my scenario:

    I have a View layer (named 'MainForm') connected to my Presentation layer (named 'MainFormPresentation') via an Interface. The interface (named 'IMainFormView') is defined in my Presentation layer class object just above the 'Public Class name' definition. The MainForm Class implements the Interface and raises events/defines Properties to communicate with the Presentation Layer. This works fine.

    Code Block

    Imports System.Windows.Forms
    Imports TDC.BusinessLayer
    Imports TDC.PresentationLayer
    Imports TDC.MSProjectLayer

    Public Class MainForm

        Implements IMainFormView

        'Create a private variable for the Presenter Class.
        Private mMainFormPresenter As MainFormPresentation

        'Create the Events which link back to the Presentation Layer Events.
        Public Event Initialise3DPF(ByVal sender As Object, ByVal e As System.EventArgs) Implements PresentationLayer.IMainFormView.Initialise3DPF
        Public Event OpenCampaignFile(ByVal sender As Object, ByVal e As System.EventArgs) Implements PresentationLayer.IMainFormView.OpenCampaignFile

        Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            'Create an instance of the Class (CampaignSettings) in the Presentation Layer.
            Me.mMainFormPresenter = New PresentationLayer.MainFormPresentation(Me)

            RaiseEvent Initialise3DPF(Me, EventArgs.Empty)
        End Sub

        Private Sub OpenCampaignToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenCampaignToolStripMenuItem.Click
            RaiseEvent OpenCampaignFile(Me, EventArgs.Empty)
        End Sub

        Public Property CampaignPath() As String Implements PresentationLayer.IMainFormView.CampaignPath

            End Get
            Set(ByVal value As String)

            End Set
        End Property

    End Class

    Code Block

    Imports TDC.BusinessLayer

    Public Interface IMainFormView
        Property CampaignPath() As String
        Event OpenCampaignFile As EventHandler(Of EventArgs)
        Event Initialise3DPF As EventHandler(Of EventArgs)
    End Interface

    Public Interface IMainFormProject
        'Declare Properties and Events for Presentation Layer
        'Property CampaignPath() As String
        'Event OpenProjectFileEvent As EventHandler(Of EventArgs)
        Sub OpenProjectFile()
    End Interface

    Public Class MainFormPresentation

        'Create a reference to the Interfaces above.
        'This reference represents the ViewLayer form 'MainForm'.
        Private mMainFormView As IMainFormView

        'Create a reference to the IMSProjectService interface.
        Private mMSProjectService As IMainFormProject

        Public Sub New(ByVal view As IMainFormView)

            'Pass a reference to 'mMainFormView'.
            Me.mMainFormView = view

            'Call the Initialise method.

        End Sub

        'Create a method which connects the events in the ViewLayer form
        'with the events in this Presentation Layer.
        Private Sub Initialise()
            AddHandler Me.mMainFormView.Initialise3DPF, AddressOf mMainFormView_Initialise
            AddHandler Me.mMainFormView.OpenCampaignFile, AddressOf mMainFormView_Open
        End Sub

        Private Sub mMainFormView_Initialise(ByVal sender As Object, ByVal e As System.EventArgs)

        End Sub

        Private Sub mMainFormView_Open(ByVal sender As Object, ByVal e As System.EventArgs)

                MsgBox("mMainFormView_Open PresentationLayer")

            Catch ex As Exception

            End Try
        End Sub

    End Class

    I want to implement a Microsoft Project layer (named 'MSProjectService') to separate all of the communication with Microsoft Project because I know that I will be implementing a different project planning software in the near future.

    Code Block

    Imports System.Windows.Forms
    Imports MSProject = Microsoft.Office.Interop.MSProject
    Imports TDC.PresentationLayer
    Imports TDC.BusinessLayer

    Public Class MSProjectService

        Implements IMainFormProject

        Private mPresenter As MainFormPresentation

        Private Sub New()
            Me.mPresenter = New MainFormPresentation(Me)
        End Sub

        Public Sub OpenProjectFile() Implements PresentationLayer.IMainFormProject.OpenProjectFile
                MsgBox("Open Project File.")
        End Sub

    End Class

    I created another Interface, below the 'IMainFormView' interface, in the Presentation Layer (named 'IMainFormProject') which simply has a subroutine (sub OpenProjectFile()). I implemented this in the MSProjectService Layer and defined the code for the OpenProjectFile method.

    If I raise an Event in the MainForm, having selected a menu item, I can pick this up in the Presentation Layer and call a Method in the Presentation Layer. However from here I can't seem to call the OpenProjectFile method in the MSProjectService Layer.

    Where am I going wrong please?

    Thank you.
    Friday, November 9, 2007 5:02 PM

All replies

  • Hi Chris Mollad,

    Have thought of implementing the code in MVP , MVC design. When you are dealing with complex design issues please understanding the over all technical challenges that  you are going to  face. Please talk with technical people in your group and ask their suggestion , then you can find a suitable solution to any design problem. Group design of any technical can help .

    Hope this will help you out.

    Phijo Mathew Philip.

    Thursday, March 19, 2009 6:29 PM