473,288 Members | 2,350 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,288 software developers and data experts.

Class question

Hello,

I have various classes in a project and all them use a few common
properties.
So I created a new class, named Config, with all those properties so I
don't need to define those properties in all classes.

My problem is how to make the Config properties accessible in my other
classes.

For example, I would like to use something like:

Dim myConfig As MyNamespace.Config
myConfig.Property_A = "PropertyA"
myConfig.Property_B = "PropertyB"

Dim myClass1 As MyNamespace.Class1
Class1.RunMethod1

And myClass1 would use PropertyA and PropertyB without needing to
define them in myClass1 itself.

Any idea how to create this?

Thanks,
Miguel

Mar 22 '07 #1
6 1601
Yes. If I understand you correctly.

All you have to do is to make sure that your Class1 instance has a reference
to the Config instance. You could, for instance, pass the reference in the
Class1 constructor:

If you need to access the Config instance over a wider scope, you could
store a reference to it in the Session:

Session["myconfig"] = myConfig; // or whatever you do in VB.NET

Any object can now retrieve myConfig from the Session:

Config aConfigInstance = (Config)Session["myconfig"]; // ... translated
to VB.NET

Is that what you're after?
Peter

"shapper" <md*****@gmail.comwrote in message
news:11**********************@e1g2000hsg.googlegro ups.com...
Hello,

I have various classes in a project and all them use a few common
properties.
So I created a new class, named Config, with all those properties so I
don't need to define those properties in all classes.

My problem is how to make the Config properties accessible in my other
classes.

For example, I would like to use something like:

Dim myConfig As MyNamespace.Config
myConfig.Property_A = "PropertyA"
myConfig.Property_B = "PropertyB"

Dim myClass1 As MyNamespace.Class1
Class1.RunMethod1

And myClass1 would use PropertyA and PropertyB without needing to
define them in myClass1 itself.

Any idea how to create this?

Thanks,
Miguel

Mar 22 '07 #2
On Mar 22, 3:24 pm, "Peter Bradley" <pbrad...@uwic.ac.ukwrote:
Yes. If I understand you correctly.

All you have to do is to make sure that your Class1 instance has a reference
to the Config instance. You could, for instance, pass the reference in the
Class1 constructor:

If you need to access the Config instance over a wider scope, you could
store a reference to it in the Session:

Session["myconfig"] = myConfig; // or whatever you do in VB.NET

Any object can now retrieve myConfig from the Session:

Config aConfigInstance = (Config)Session["myconfig"]; // ... translated
to VB.NET

Is that what you're after?

Peter

"shapper" <mdmo...@gmail.comwrote in message

news:11**********************@e1g2000hsg.googlegro ups.com...
Hello,
I have various classes in a project and all them use a few common
properties.
So I created a new class, named Config, with all those properties so I
don't need to define those properties in all classes.
My problem is how to make the Config properties accessible in my other
classes.
For example, I would like to use something like:
Dim myConfig As MyNamespace.Config
myConfig.Property_A = "PropertyA"
myConfig.Property_B = "PropertyB"
Dim myClass1 As MyNamespace.Class1
Class1.RunMethod1
And myClass1 would use PropertyA and PropertyB without needing to
define them in myClass1 itself.
Any idea how to create this?
Thanks,
Miguel
Not really.

I suppose the way to go is to make Class1 to Inherit from class
Config. I think.

Mar 22 '07 #3

"shapper" <md*****@gmail.comwrote in message
news:11*********************@l75g2000hse.googlegro ups.com...
On Mar 22, 3:24 pm, "Peter Bradley" <pbrad...@uwic.ac.ukwrote:
>Yes. If I understand you correctly.

All you have to do is to make sure that your Class1 instance has a
reference
to the Config instance. You could, for instance, pass the reference in
the
Class1 constructor:

If you need to access the Config instance over a wider scope, you could
store a reference to it in the Session:

Session["myconfig"] = myConfig; // or whatever you do in VB.NET

Any object can now retrieve myConfig from the Session:

Config aConfigInstance = (Config)Session["myconfig"]; // ...
translated
to VB.NET

Is that what you're after?

Peter

Not really.

I suppose the way to go is to make Class1 to Inherit from class
Config. I think.
Only if Class1 IS-A Config. Otherwise you're breaking just about every rule
in OOP.

But if you explained why it's not really what you want, someone might be
able to help.
Peter
Mar 22 '07 #4
On Mar 22, 4:42 pm, "Peter Bradley" <pbrad...@uwic.ac.ukwrote:
"shapper" <mdmo...@gmail.comwrote in message

news:11*********************@l75g2000hse.googlegro ups.com...
On Mar 22, 3:24 pm, "Peter Bradley" <pbrad...@uwic.ac.ukwrote:
Yes. If I understand you correctly.
All you have to do is to make sure that your Class1 instance has a
reference
to the Config instance. You could, for instance, pass the reference in
the
Class1 constructor:
If you need to access the Config instance over a wider scope, you could
store a reference to it in the Session:
Session["myconfig"] = myConfig; // or whatever you do in VB.NET
Any object can now retrieve myConfig from the Session:
Config aConfigInstance = (Config)Session["myconfig"]; // ...
translated
to VB.NET
Is that what you're after?
Peter
Not really.
I suppose the way to go is to make Class1 to Inherit from class
Config. I think.

Only if Class1 IS-A Config. Otherwise you're breaking just about every rule
in OOP.

But if you explained why it's not really what you want, someone might be
able to help.

Peter
Hello,

Let me try to explain it better.

Basically I have a library project with 12 classes under the same
namespace.

All these classes access an SQL 2005 database and need a connection
string.

However, I want the user to define the connection string when using
these classes.

But I want the connection string to be defined only once and be used
by all classes.

Of course I could add a ConnectionString property to every class but
this does not seem the best way to do this.

Basically that's it.

What should be the best way to do this?

Thanks,

Miguel

Mar 22 '07 #5
On Mar 22, 3:45 pm, "shapper" <mdmo...@gmail.comwrote:
On Mar 22, 4:42 pm, "Peter Bradley" <pbrad...@uwic.ac.ukwrote:


"shapper" <mdmo...@gmail.comwrote in message
news:11*********************@l75g2000hse.googlegro ups.com...
On Mar 22, 3:24 pm, "Peter Bradley" <pbrad...@uwic.ac.ukwrote:
>Yes. If I understand you correctly.
>All you have to do is to make sure that your Class1 instance has a
>reference
>to the Config instance. You could, for instance, pass the reference in
>the
>Class1 constructor:
>If you need to access the Config instance over a wider scope, you could
>store a reference to it in the Session:
>Session["myconfig"] = myConfig; // or whatever you do in VB.NET
>Any object can now retrieve myConfig from the Session:
>Config aConfigInstance = (Config)Session["myconfig"]; // ...
>translated
>to VB.NET
>Is that what you're after?
>Peter
Not really.
I suppose the way to go is to make Class1 to Inherit from class
Config. I think.
Only if Class1 IS-A Config. Otherwise you're breaking just about every rule
in OOP.
But if you explained why it's not really what you want, someone might be
able to help.
Peter

Hello,

Let me try to explain it better.

Basically I have a library project with 12 classes under the same
namespace.

All these classes access an SQL 2005 database and need a connection
string.

However, I want the user to define the connection string when using
these classes.

But I want the connection string to be defined only once and be used
by all classes.

Of course I could add a ConnectionString property to every class but
this does not seem the best way to do this.

Basically that's it.

What should be the best way to do this?

Thanks,

Miguel- Hide quoted text -

- Show quoted text -
Miguel,

Is your application an ASP.NET application, or a Windows Forms
application? Also, which verison of .NET are you targeting? 1.0, 1.1.,
or 2.0?

The place you want to store your connection string in is your
application's configuration file. However, getting at that data
differs depending on which version of the Framework you're targeting
(and potentially the type of application you're writing).

Thanks!
Mike

Mar 22 '07 #6
On Mar 22, 7:59 pm, "Mike Hofer" <kchighl...@gmail.comwrote:
On Mar 22, 3:45 pm, "shapper" <mdmo...@gmail.comwrote:
On Mar 22, 4:42 pm, "Peter Bradley" <pbrad...@uwic.ac.ukwrote:
"shapper" <mdmo...@gmail.comwrote in message
>news:11*********************@l75g2000hse.googlegr oups.com...
On Mar 22, 3:24 pm, "Peter Bradley" <pbrad...@uwic.ac.ukwrote:
Yes. If I understand you correctly.
All you have to do is to make sure that your Class1 instance has a
reference
to the Config instance. You could, for instance, pass the reference in
the
Class1 constructor:
If you need to access the Config instance over a wider scope, you could
store a reference to it in the Session:
Session["myconfig"] = myConfig; // or whatever you do in VB.NET
Any object can now retrieve myConfig from the Session:
Config aConfigInstance = (Config)Session["myconfig"]; // ...
translated
to VB.NET
Is that what you're after?
Peter
Not really.
I suppose the way to go is to make Class1 to Inherit from class
Config. I think.
Only if Class1 IS-A Config. Otherwise you're breaking just about every rule
in OOP.
But if you explained why it's not really what you want, someone might be
able to help.
Peter
Hello,
Let me try to explain it better.
Basically I have a library project with 12 classes under the same
namespace.
All these classes access an SQL 2005 database and need a connection
string.
However, I want the user to define the connection string when using
these classes.
But I want the connection string to be defined only once and be used
by all classes.
Of course I could add a ConnectionString property to every class but
this does not seem the best way to do this.
Basically that's it.
What should be the best way to do this?
Thanks,
Miguel- Hide quoted text -
- Show quoted text -

Miguel,

Is your application an ASP.NET application, or a Windows Forms
application? Also, which verison of .NET are you targeting? 1.0, 1.1.,
or 2.0?

The place you want to store your connection string in is your
application's configuration file. However, getting at that data
differs depending on which version of the Framework you're targeting
(and potentially the type of application you're writing).

Thanks!
Mike
Hi Mike,

I am creating a class library and the target will be Asp.Net 2.0 web
sites.
So I think the options would be:
1. The user defines a connection string in its code and "indicates" my
classes to use it.
2. The user defines a connection string in its web site Web.Config
file and "indicates" the classes to use is.

Anyway, I am not sure the way to go on this.
Sure I could force the user to create a connection string named
"ClassMig" and then in my classes I would get that connection string.

But this is not the way I wanna do it.

Thanks,
Miguel

Mar 22 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Bryan Parkoff | last post by:
I find an interesting issue that one base class has only one copy for each derived class. It looks like that one base class will be copied into three base classes while derived class from base...
20
by: modemer | last post by:
Question is as in subject. For example: class BaseClass { public: void func() { do something; } // I don't want this function being overloaded in its inherited class };
1
by: Alfonso Morra | last post by:
if I have a class template declared as ff: (BTW is this a partial specialization? - I think it is) template <typename T1, myenum_1 e1=OK, my_enum_2=NONE> class A { public: A(); virtual...
21
by: Jon Slaughter | last post by:
I have a class that is basicaly duplicated throughout several files with only members names changing according to the class name yet with virtually the exact same coding going on. e.g. class...
0
by: Sebastian Hiller | last post by:
Hello, i'm new to .Net (i'm using VB as language and i'm working in the code-behind mode) and i can't solve the following problem: I have a WebForm and want to Add a UserControl...
6
by: rodchar | last post by:
Hey all, I'm trying to understand Master/Detail concepts in VB.NET. If I do a data adapter fill for both customer and orders from Northwind where should that dataset live? What client is...
2
by: Chris Puncher | last post by:
Hi. I have a RCW class that was generated by the VS.NET2003 IDE when I added a COM dll reference to my project. This all works fine when I call methods on it. My initial problem is that in...
9
by: needin4mation | last post by:
I have a .aspx file and it's src. I also have a third file, a class that the src references. Everything is in the same directory/folder. Everything has the same namespace. How do I reference the...
43
by: Tony | last post by:
I'm working with GUI messaging and note that MFC encapsulates the message loop inside of a C++ class member function. Is this somehow inherently less robust than calling the message loop functions...
2
by: K Viltersten | last post by:
Suppose there is the following class structure. class S {...} class A : S {...} class B : S {...} class A1 : A {void m(){...}} class B1 : B {void m(){...}} class B2 : B {...} Just to clarify...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.