2

I am trying to make an ATM Application in .NET Framework using C#. I have implemented some part of it using 3 tier architecture.

As the user chooses to withdraw cash, flow moves from VIEW to LogicLayer as I have added reference of VIEW in LogicLayer. Now I need to call a method of view from LogicLayer. Can some one tell me how to do that?

Thanks

class DataAccessLayerClass
{
    BusinessObjectClass read(BusinessObjectClass bo)
    {
        //read from file if user exists then return his credentials

        //else
        //call INVALID USERNAME / PASSWORD errror method in VIEW. 
    }
}

I can flow from VIEW to LL and DAl, but how to flow in reverse direction? As desired in this case

Muhammad Arsalan
  • 345
  • 4
  • 14
  • 1
    Could you post some code? – Jeroen Heier Mar 13 '16 at 08:01
  • Have a read about using MVVM (Model-View-ViewModel) with WPF. This should provide you with the functionality you need to build a multi-layered application in C#. – stuartmclark Mar 13 '16 at 08:04
  • @Jeroen I can flow from VIEW to LL and DAL, but how to flow in reverse order manually in this case? Pseudo-code added in description – Muhammad Arsalan Mar 13 '16 at 08:23
  • You don't, that's the point – Jeff Mercado Mar 13 '16 at 08:39
  • I would like to give a simple suggestion, which is not a proper answer: when deciding where to put your code, think first about responsibility. Who is responsible for what? The view must show, the logic layer must "decide", the data layer must read and write. It's not really important what the responsibility is (it changes depending upon the specific architecture you are using), the fundamental thing is that you should always know where to put some code, depending upon responsibility. This is called separation of concerns. – Alberto Chiesa Mar 13 '16 at 10:45

2 Answers2

1

The whole idea of a layered architecture is that layers are opaque and layers above depend only on the layers below, not vice versa, so you should not have a direct dependency on your view in your business (logical) layer. The UI should send a request to and then react to the response of your business layer, possibly through application service layer. How exactly do you do this, and what pattern you utilize, MVVM, MVC, MVP - depends on your technology stack, so please share more details

ironstone13
  • 3,325
  • 18
  • 24
0

Do not try to use functionalities of view on the business layer. This is the destruction of your application structure. You have to think just one way connection. Not a dialog. For example: View can call logic layer and returns a result. Then AGAIN view calls logic according to result.

ahmet
  • 702
  • 1
  • 10
  • 29
  • That means instead of calling VIEW from BLL of DAL, I need to keep some checks in VIEW on what is returned by lower layers. All my code depends on responses given by lower layers. Did I took I right? – Muhammad Arsalan Mar 13 '16 at 09:59
  • Yes. Your view is the layer where actions start. User makes an action on UI(view layer). You should make some checks on UI. Then view layer sends data to business layer. Business layer also makes controls according to request, and communicates with DAL. DAL returns some results and business layer returns data to view. Then view again makes some controls and requests another data from business layer. This is the cycle of n tier application. One way communication. If you reference your view dll to business or dal then you probably make mistake. – ahmet Mar 13 '16 at 10:10