Solved

C# Exposing classes to layers

Posted on 2007-11-20
7
1,123 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
7 Comments
 
LVL 22

Expert Comment

by:p_davis
Comment Utility
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
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 12

Expert Comment

by:AGBrown
Comment Utility
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
Comment Utility
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
Comment Utility
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 300 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now