0

I am currently working on a project that is fairly small for the time being. There was a recent change to implement 3-tier architecture, such that the code is now split up appropriately to data access, business logic and user interface tiers. However, there is no use of objects outside of creating them to ultimately call a data access method.

At a very basic level, pretty much everything we do is:

    Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Dim dt As New DataTable
        dt = objBl.GetSomething
        'Assign to Grid
        'Format Grid
    End Sub

I want to implement something more like:

Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    Dim lstSomeObject As New List(Of SomeObject)
    'Populate list of objects by calls to business layer
    DataGridView1.DataSource = lstSomeObject
    'Format Grid
End Sub

Ultimately, not much different. But instead of us having to pass thirty variables through to get a resultant data table that is used once, we could create an object (and lists of objects) and pass these around instead. I have a couple years experience working in such an environment, but zero experience in converting to such an environment. Frankly, I am at a loss as to how to do this.

Do I create a separate entities project for this, and then does everything reference this? Or do I force our current objects to store both the properites and methods for each object type (this way feels counter-intuitive to me)? Or something else entirely? I have searched around most of the weekend and have not found anything overly helpful.

2
  • 1
    What you describe is more of a 3-layered system than a 3-tier one.
    – jhominal
    Mar 2 '14 at 19:09
  • Yes, I suppose that is true. Hence part of the need for the question. I only kind of know what I'm doing. Mar 2 '14 at 19:11
2

It sounds like you're describing a data transfer object or more commonly known as a DTO.

The biggest advantage of a DTO is just as you said - avoiding having to pass around 30 variables.

Using DTOs is a good first step for moving into a n-tier architecture which is sounds like you may be trying to achieve. An n-tier architecture takes advantage of several OOP principles such as encapsulation in order to make your overall application more maintainable.

Do I create a separate entities project for this, and then does everything reference this?

Yes, that's generally the easiest way and cuts down on duplicated code. Your layers that access the DTO may have to test for a valid value, but that's about the worst of it.

1
  • Thanks for the answer. This is essentially what I did, after some discussion amongst the team. In our BusinessLogic layer, there is now DomainObjects project that houses the various object definitions. Mar 9 '14 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.