Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C# Exposing classes to layers

Posted on 2007-11-20
7
Medium Priority
?
1,134 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
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

886 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