Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# Exposing classes to layers

Posted on 2007-11-20
7
Medium Priority
?
1,132 Views
Last Modified: 2013-12-17
I have 3 layers  1) Client  2)Business Access Layer  3) DataAccessLayer

Client interacts with Business Access Layers which return Datasets  and Integer values
Business Access Layer  Just has a Reference added in bin and on top (Using  Namespace.DAL) and it requests the respective functions from DAL Layer. Client interacts with BAL only.

BAL Layer  has all functions as Public /  DAL Layer has all functions as public
Should I chang the DAL layer functions to protected Friend etc( BAL doesnot inherit from DAL Again)
It only has reference of DAL DLL
0
Comment
Question by:dotnet0824
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 22

Expert Comment

by:p_davis
ID: 20329059
which .net platform are you using

if 3.0 you can use wcf servicemodel and create your functions as part of an interface that a class can implement
0
 
LVL 12

Expert Comment

by:AGBrown
ID: 20329467
Do your BAL classes inherit from the DAL? Usually your BAL would construct and use the DAL classes, but not inherit from them - so protected access modifiers are therefore useless to hide the DAL from the client. If you have layered, but not tiered your application, the easiest thing to do is construct a DAL assembly, reference that from the BAL assembly, and only reference the BAL assembly from the DAL assembly - that should keep everything decoupled. If you are passing around typed objects for data, then you can keep those in yet another assembly that all layers can access.

Andy
0
 

Author Comment

by:dotnet0824
ID: 20330077
I am using .NET 2.0 CSharp Visualstudio.NET 2005. No my BAL just has a Reference to the DAL as said earlier.  Its a Solution actually containing   Namespace :  BIZ.DAL  / BIZ.BAL
BIZ.BAL is exposed to the client.. it uses it and invokes the functions.. BAL only contains Skeleton of the functions...--- BAL requests the DAL for the Data which in turns has all the Database Operations.
BAL is just a skeleton of all the functions which exist in the DAL.  Both are public Classes and Both have Public Functions (ie DAL/BAL)............ I want in such a way that  If Client using the Assembly BIZ.DAL he should be able to instantiate it........ Normally client should have access to that BIZ.DAL right . incase client has then we have to restrict it right. Hope its clear
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:AGBrown
ID: 20330554
Normally I would say that your client would not have any access to the DAL at all - all interaction with data should go through the BAL. That way you don't have to worry about the access modifiers on the DAL. Your DAL and your BLL should be in two separate assemblies if you are worried, and that will fix everything. As I say - if you need to pass data objects, they can be in a third assembly which the DAL, BLL and client use. All the business logic is then in the BLL, all the data object-database logic is in the DAL.
0
 

Author Comment

by:dotnet0824
ID: 20330683
Points have been increased.  Got you.  Why Shouldnt the BAL inherit DAL? Is it a wrong concept  can it be explained. Currently BAL has just got a Reference of DAL
0
 
LVL 1

Expert Comment

by:arshadd
ID: 20333137
In BAL u have ur business logic i.e. may be for some business case you have to call multiple DAL methods. Its not logical to inherit BAL with DAL. Both are service classes which provide services to there user i.e DAL will provide services to BAL. I hope its clear.
0
 
LVL 12

Accepted Solution

by:
AGBrown earned 1200 total points
ID: 20335171
Referencing is fine - by inheriting I am refering to polymorphism and inheritance, e.g. (quick and dirty example):

public BALUser: DAL.DALUser
{
    public User CreateUser(string userName)
    {
        base.InsertUser(userName);
        return base.GetUserByName(userName);
    }
}

You wouldn't do this, rather you would do
public BALUser
{
    public User CreateUser(string userName)
    {
        DAL.DALUser.InsertUser(userName);
        return DAL.DalUser.GetUserByName(userName);
    }
}

So you aren't inheriting, you are just using the methods of the user class in a piece of business logic. The DAL is therefore not referenced by the client classes and so you don't have to worry about the clients using the DAL. The User object is in a third assembly, which is reference by all the layers.

Normally Business Logic implies conditional logic - such as testing the username for length, politeness of the words etc etc. The DAL would control the interaction with the database. The BAL classes don't want to know about the data storage layer. You may use multiple data classes in one BAL - so inheritance may not be such a good idea.

If you want to know more about layering data applications, and I am not promoting this book despite recommending it so often in my answers, take a look at Martin Fowler's Patterns of Enterprise Application Architecture - it tells you a lot more about the types of BL patterns, and the DAL patterns that go with them.

Andy
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question