I'm working on a VB.Net DLL project. It has 6 classes. One of the classes
has the properties for the database path, database name and server name. The
purpose of this class is so that the DLL can be tested on different servers.
Without using the keyword "Shared", how can I share these data to the other
5 classes?
Thanks for any ideas!
Cesar 6 3273
Cesar,
Oh! out of curiosity, why do you not want to use "Shared"?
Hope this helps
Jay
"cksj" <ck*******@hotm ail.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. .. I'm working on a VB.Net DLL project. It has 6 classes. One of the classes has the properties for the database path, database name and server name.
The purpose of this class is so that the DLL can be tested on different
servers. Without using the keyword "Shared", how can I share these data to the
other 5 classes?
Thanks for any ideas!
Cesar
Cesar,
Without Shared, each consumer of the class will need to create an instance
of the class then access the properties. Which for this sort of thing the
Singleton Pattern is better, you do however need to use Shared to implement
a Singleton.
You could make the class itself a Singleton, when means the properties will
not be marked shared, however a read only shared Instance field will be
created in the class.
Public Class DbSettings
Public Shared Readonly Instance As New DbSettings()
Private Sub New()
End Sub
Public Property DatabasePath...
End Class
Then whenever you need to use any of the properties of the class you use
DbSettings.Inst ance.DatabasePa th.
Hope this helps
Jay
"cksj" <ck*******@hotm ail.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. .. I'm working on a VB.Net DLL project. It has 6 classes. One of the classes has the properties for the database path, database name and server name.
The purpose of this class is so that the DLL can be tested on different
servers. Without using the keyword "Shared", how can I share these data to the
other 5 classes?
Thanks for any ideas!
Cesar
Cesar,
You would have to make the other classes create your
settings class internally. That would make it fairly
loosely coupled, so you can test it on various backends.
I'd say though, that if that is a helper type class, you
might at least want consider why you wouldn't want to
make it shared (or static as it is in C#)
Somewhere or other you need to make the database settings
class instance available within the memory spaces of the
other 5 classes. To me, those are your two choices. If
you're creating internally, then you have plenty of
choices on how you might then go about doing this. If
the 5 classes need the settings directly, then you could
create a private property that controls the creation of
the settings object for the user of the other 5 classes,
or you could create it when the class in created, or you
could create and destroy it only when it is needed to
name but a few ways....
Hope that's of help.... -----Original Message----- I'm working on a VB.Net DLL project. It has 6 classes.
One of the classeshas the properties for the database path, database name
and server name. Thepurpose of this class is so that the DLL can be tested
on different servers.Without using the keyword "Shared", how can I share
these data to the other5 classes?
Thanks for any ideas!
Cesar
.
If you have a dbconnection object that you want the other 5 classes to use
the classic approach would be to just dim the db class object and pass it
along to each method that requires in in the other classes
so you would just have a method like
public function getItem(ses as dbconnection, itemCode as string) as class1
"cksj" <ck*******@hotm ail.com> wrote in message
news:#Z******** ******@tk2msftn gp13.phx.gbl... I'm working on a VB.Net DLL project. It has 6 classes. One of the classes has the properties for the database path, database name and server name.
The purpose of this class is so that the DLL can be tested on different
servers. Without using the keyword "Shared", how can I share these data to the
other 5 classes?
Thanks for any ideas!
Cesar
Jay,
Thanks for your help.
I read that using Shared in DLL is not the best practice to use.
Cesar
"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in message
news:OS******** ******@TK2MSFTN GP12.phx.gbl... Cesar, Oh! out of curiosity, why do you not want to use "Shared"?
Hope this helps Jay
"cksj" <ck*******@hotm ail.com> wrote in message news:%2******** ********@tk2msf tngp13.phx.gbl. .. I'm working on a VB.Net DLL project. It has 6 classes. One of the
classes has the properties for the database path, database name and server name. The purpose of this class is so that the DLL can be tested on different servers. Without using the keyword "Shared", how can I share these data to the other 5 classes?
Thanks for any ideas!
Cesar
Cesar, I read that using Shared in DLL is not the best practice to use.
Correct Shared should not be your first choice, however there are times when
it is appropriate. It depends on the type of app. Like any construct
available in .NET its usage has its pros & cons.
As I said in my other email, you need to use it for the Singleton Pattern,
what you asked sounds like a good application of the Singleton Pattern,
assuming this is not an ASP.NET app. ASP.NET apps you need to use session &
context aware methods of implementing a singleton. Which is where public
shared methods (properties, subs & functions) are better than public shared
fields. You can change the code of the method to better anticipate the
environment you are running it.
The Singleton Pattern is a common OOP Design Pattern to allow global access
to an object. For details on the Singleton Patten and other Design Patterns
see:
1. "Design Patterns - Elements of Reusable Object-Oriented Software" by the
GOF (Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides)
2. "Patterns of Enterprise Application Architecture" by Martin Fowler
3. "Visual Basic Design Patterns - VB 6.0 and VB.NET" by James W. Cooper.
#3 is a good companion for #1, #2 shows some advanced patterns. All three
are from Addison Wesley.
Hope this helps
Jay
"cksj" <ck*******@hotm ail.com> wrote in message
news:ey******** ******@TK2MSFTN GP09.phx.gbl... Jay,
Thanks for your help. I read that using Shared in DLL is not the best practice to use.
Cesar
"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in
message news:OS******** ******@TK2MSFTN GP12.phx.gbl... Cesar, Oh! out of curiosity, why do you not want to use "Shared"?
Hope this helps Jay
"cksj" <ck*******@hotm ail.com> wrote in message news:%2******** ********@tk2msf tngp13.phx.gbl. .. I'm working on a VB.Net DLL project. It has 6 classes. One of the classes has the properties for the database path, database name and server
name. The purpose of this class is so that the DLL can be tested on different servers. Without using the keyword "Shared", how can I share these data to the other 5 classes?
Thanks for any ideas!
Cesar
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: cksj |
last post by:
I'm working on a VB.Net DLL project. It has 6 classes. One of the classes
has the properties for the database path, database name and server name. The
purpose of this class is so that the DLL can be tested on different servers.
Without using the keyword "Shared", how can I share these data to the other
5 classes?
Thanks for any ideas!
Cesar
|
by: Newbee Adam |
last post by:
anyone have any secrets or pearls about vb.net you want to share
I was asked by my company to begin teach an introductory VB.Net course
2 day seminar. I had been teaching an sql server 2000 seminar.
The brochure they send out for the class creates a high expectation (those
marketers )
that a trainer has to fill. This brochure is entitled "DISCOVERING the
SECRETS of vb.net"
|
by: Tony Fonager |
last post by:
I am currently developing a statistics system in ASP.NET, and need to share
information about the customers websites, in this application.
(I have simplified my code, to make my project easier to explain.)
The simple version of the system is like this : A customer inserts HTML code
on his webpage, which contacts my statistics server each time the customers
website recieves a hit - like a classic "register website traffic" system.
...
|
by: Quentin Huo |
last post by:
Hi:
I have two web sites in my IIS. I want them to share or use one set of
classes that I created, because they have same functions that the classses
provide. And maybe in the future I will create more web sites to use the set
of classes. But I don't know how to do this. Where do I need to put the set
of classes? Do I have to make them be DLLs?
Thanks
|
by: csharpula csharp |
last post by:
Hello,
I want to share some data between my classes.
All of the classes may get or set this data .
The Application is Gui application and each tab of it is a class , there
is a data which is mutual to all classes such as if im Tab 1 a user will
upload a file ,the name of this file suppose to be avalible to all the
other Tabs (classes).
How can I slove this ?
Thanks!
| |
by: viettrung |
last post by:
Hi,
I have two classes that share a common data list (specifically, a std::vector). This data list should be accessed by the two classes only, so I think using a global variable is not a good solution. Actually I am so confused to find an elegant way to store such common data for the two.
If you have any idea about that, please let me know.
Thanks alot!
.viettrung.
|
by: Immortal Nephi |
last post by:
First class is the base class. It has two data: m_Base1 and m_Base2.
Second class and third class are derived classes and they are derived
from first class. m_Base1 and m_Base2 are inherited into two derived
classes.
Second class has its own m_Base1 and m_Base2 and third class does the
same. I am curious. How can second class and third class share the
same m_Base1 and m_Base2?
You define second class first and enter data into...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |