none
Static Class in Business Layer RRS feed

  • Question

  • hi,

      Generally in DAL layer i used to write one Static Helper class which includes the general db operations by passing SP as parameter. So in the DAL classes i just use this static class to avoid entire code duplication in all methods. This is used in the same layer.

    Now in the presentation layer i am using Numeric checking and some common validations in each  form. Instead of duplicate the method in each form can i write the same in one static class in Business Layer. Is the best practice or can i write one class in the same presentation layer.

    My doubts are

    1. Here Static class in Business Layer is advisable / non static class in Business Layer / normal class in presentation layer?

    2. If static in business layer then if i include WCF as a service layer between business and presentation which is advisable?

     

    Monday, October 29, 2012 4:11 PM

Answers

  • " business relate common is in business layer and if any common for presentation than create a common class in presentation itself"

    -A WCF application (BAL/DAL/other) should be complete in itself.

    -A client (UI Layer) using a WCF application if want to apply some validation on data before posting to WCF end point that is the UI Validations, however our BAL should be capable to validate these and throw appropriate custom exceptions to indicate the client about any invalid data. 

    Please do not mix a client (UI in your case) with a different WCF application (your BAL).

    If your WCF application is only for one client (not generic, in your case this seems to be true) then your WCF application can (not advocating this practice, but as I said earlier our solution is toward our ultimate objective) assume the some initial validation will be done by UI and BAL will receive validated data then you can write these validation with UI Layer. 



    • Proposed as answer by akfi Thursday, November 8, 2012 6:13 AM
    • Marked as answer by akhilrajau Wednesday, November 14, 2012 12:02 PM
    Thursday, November 8, 2012 6:13 AM

All replies

  • not any help friends
    Friday, November 2, 2012 2:10 AM
  • Personally I don't care, but there are lot of tooling support for non-static methods, especially around testing mechanisms. So I would think the general rule of thumb is to avoid statics wherever you can. As I say I'm not a great follower of that, but I'm in a tiny minority and equally I don't feel that strongly about it.


    http://pauliom.wordpress.com

    Friday, November 2, 2012 2:17 AM
  • Numeric checking and some common validations in each  form.

    My Views are as follows, very particular to your problem statement.

    -common validations in each  form: should go to base form and all other form should inherit this.

    -Numeric checking: this part can go in static helper class.

    Tuesday, November 6, 2012 4:26 AM
  • ya common validation means Numeric Checking, Email check etc. so you suggest static helper class in business layer. So what about my second question
    Tuesday, November 6, 2012 2:55 PM
  • -If static in business layer then if i include WCF as a service layer between business and presentation which is advisable?

    This solution should be designed on the type of validation.  If  a validation is integral part of any business layer functionality, then no reason to separate this from Business Layer. This has to developed and deploy as a part of Business Layer itself.  

    Actually when we need to move "Business Layer on a different tier or in SOA" , its the objective which will govern our design. 



      Mark answered if find helpful.

    Wednesday, November 7, 2012 9:41 AM
  • k thanks. If my understanding is wrong please correct me. So you told that business relate common is in business layer and if any common for presentation than create a common class in presentation itself.
    Wednesday, November 7, 2012 2:31 PM
  • " business relate common is in business layer and if any common for presentation than create a common class in presentation itself"

    -A WCF application (BAL/DAL/other) should be complete in itself.

    -A client (UI Layer) using a WCF application if want to apply some validation on data before posting to WCF end point that is the UI Validations, however our BAL should be capable to validate these and throw appropriate custom exceptions to indicate the client about any invalid data. 

    Please do not mix a client (UI in your case) with a different WCF application (your BAL).

    If your WCF application is only for one client (not generic, in your case this seems to be true) then your WCF application can (not advocating this practice, but as I said earlier our solution is toward our ultimate objective) assume the some initial validation will be done by UI and BAL will receive validated data then you can write these validation with UI Layer. 



    • Proposed as answer by akfi Thursday, November 8, 2012 6:13 AM
    • Marked as answer by akhilrajau Wednesday, November 14, 2012 12:02 PM
    Thursday, November 8, 2012 6:13 AM
  • Hi

    1) Just be careful that you restrict yourself to 'common' formatting functions etc. - ZERO business logic.

    2) I recently heard someone mention that static methods are slower .... not too sure about this but maybe do some more research first.


    I.W Coetzer

    Thursday, November 8, 2012 8:33 PM
  • k thanks . i am already in research for this
    Friday, November 9, 2012 1:32 AM
  • Careful not to mix tiers and layers here. There is nothing wrong in having a "Business Layer" validation DLL running in the "Presentation Tier".

    http://pauliom.wordpress.com

    Monday, November 12, 2012 10:16 AM