StrataFrame Forum

Project Dependency Problem

http://forum.strataframe.net/Topic22098.aspx

By Bill Cunnien - 2/26/2009

Here is a layout of my projects (in brief) in my current solution:



ProjectA (MyApp.ProjectA)

Form1

Form2



ProjectB (Namespace: MyApp.ProjectB)

Form1

Form2

Reports (Folder)

Report1 (Namespace: MyApp.ProjectB.Reports.Report1)



ProjectC (Namespace: MyApp.ProjectC)

BusinessObject1

BusinessObject2

BusinessObject3



ProjectA and ProjectB reference ProjectC (no problems there!). ProjectB has a reference to ProjectA. Now, I want to print ProjectB's report from Form1 of ProjectA. I cannot reference ProjectB in ProjectA...that would cause a circular reference. What do I do?



Should I consider moving all reports out of the project that they belong in and create a separate Reports project to store any reports in the application?



Thanks for the help!!

Bill
By Trent L. Taylor - 2/26/2009

Welcome to the world of inheritance...and there are a number of ways to go about this.  We actually have a section in training where we talk about this. 

The situation that you are dealing with is ideal for interfaces.  Basically you need to move something up the food chain.  So you either need to move classes further upstream...or create interfaces that are further upstream and then implemented on the classes.  Then to prevent the circular reference, you type instance references that you are fighting as the interface instead of the actual class.

The Interface

Public Interface MyInterface

    ''' <summary>
    ''' Define properties
    ''' </summary>
    Property IsReady() As Boolean

    ''' <summary>
    ''' Define methods
    ''' </summary>
    Function Execute() As Boolean

End Interface

The Class

Public Class MySampleClass
    Implements MyInterface

    ''' <summary>
    ''' Implement the execute method from the interface
    ''' </summary>
    Public Function Execute() As Boolean Implements MyInterface.Execute
        '-- Do something here
    End Function

    ''' <summary>
    ''' Define the property and implement the IsReady property of the interface
    ''' </summary>
    ''' <remarks></remarks>
    Private _IsReady As Boolean = False
    Public Property IsReady() As Boolean Implements MyInterface.IsReady
        Get
            Return _IsReady
        End Get
        Set(ByVal value As Boolean)
            _IsReady = value
        End Set
    End Property

End Class

Typing the Class as an Interface

''' <summary>
''' This class will accept the interface instead of the object instance
''' </summary>
Public Class AnotherTestClass

    Public Sub TestingInterface(ByVal e As MyInterface)
        '-- Use the interface
        If e.IsReady Then e.Execute()
    End Sub

End Class

Using the Interface Instead of the Instance

Public Class FinalTest

    Public Sub FinalTest()
        Dim x As New AnotherTestClass()
        Dim y As New MySampleClass()

        x.TestingInterface(y)

    End Sub

End Class

By Bill Cunnien - 2/27/2009

I'd love to attend training one day. I'll do my best to digest what you have provided. Hopefully, I can get on track quickly with this.



Thanks!!

Bill