Solved

shared classes and function in asp.net application

Posted on 2010-09-16
5
376 Views
Last Modified: 2012-08-13
when is it appropriate to use shared classes. Are there any adavantages/disadv. to using non-shared functions.

For a data access layer would it be ideal to use a shared class. Please suggest.
0
Comment
Question by:TrialUser
5 Comments
 
LVL 7

Accepted Solution

by:
klakkas earned 167 total points
ID: 33691137
My rule of thumb is the following:

Use a Shared class if all the code that uses this class works under the same settings. This way, you only initialize the Class once and everyone has very fast access to it.

The example you use of the Data Access Layer is ideal. When your application wants to get data from a DB, if you don't use a shared class you would have to initialize the connection every single time. Using Shared Class, you only initialize the connection once and you can access it from anywhere in your program.

Finally, using Shared Classes reduces the coding.
With non Shared, you should do
Dim obj as new myObject
Res = obj.doWork

As with shared, you just say
Res = myObject.doWork
0
 
LVL 25

Assisted Solution

by:Luis Pérez
Luis Pérez earned 167 total points
ID: 33691142
For my data access layer I always use shared functions. I think if not neccesary to instantiate explicit objects of my DAL to call data methods.

Think in shared functions this way. Do you really need to create a instance of an object to call a method or function that doesn't need to use any data of that object itself?

Hope that helps.
0
 
LVL 7

Expert Comment

by:ajolly
ID: 33691146
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 166 total points
ID: 33691278
Well, part of my standard Data Access library is implemented as an abstract factory, which means static/shared methods for creating database objects. Ditto for specific data manager classes. A method that retrieve Customers from the database, for example, isn't necessarily going to benefit from being in a concrete object if it is literally only acting as a proxy for a database procedure.
0
 

Author Closing Comment

by:TrialUser
ID: 33781801
thanks
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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.…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

19 Experts available now in Live!

Get 1:1 Help Now