Solved

C# Exposing classes to layers

Posted on 2007-11-20
7
1,130 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
Veeam gives away 10 full conference passes

Veeam is a VMworld 2017 US & Europe Platinum Sponsor. Enter the raffle to get the full conference pass. Pass includes the admission to all general and breakout sessions, VMware Hands-On Labs, Solutions Exchange, exclusive giveaways and the great VMworld Customer Appreciation Part

 
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 300 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

Stack Overflow Podcast - Frustrating Miracles

In this podcast, Stack Overflow interviewed Linux Academy CEO/Founder, Anthony James, and got his developer story!

"Follow your passion, be prepared to work hard and sacrifice, and, above all, don't let anyone limit your dreams."  - Donovan Bailey

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

630 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