?
Solved

shared classes and function in asp.net application

Posted on 2010-09-16
5
Medium Priority
?
416 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
[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
5 Comments
 
LVL 7

Accepted Solution

by:
klakkas earned 668 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 668 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 664 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

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

771 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