473,698 Members | 2,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Class Library: multiple classes

I have a class library which contains 3 classes; one exposes all its
behaviours and the other two are used internally by the public class. My
problem is that although I can create an instance of the subservient classes,
I cannot see the methods in them from the public class.

Could someone guide me on this or give me a template?
Thanks.
Oct 4 '07 #1
6 3676
On Oct 4, 8:29 am, AA2e72E <AA2e...@discus sions.microsoft .comwrote:
I have a class library which contains 3 classes; one exposes all its
behaviours and the other two are used internally by the public class. My
problem is that although I can create an instance of the subservient classes,
I cannot see the methods in them from the public class.

Could someone guide me on this or give me a template?
Thanks.
Sounds like the methods in the subservient classes are defined as
Private. To see them from the primary class in the class library, they
will need to be either Public or Friend.

Oct 4 '07 #2
On Oct 4, 1:29 pm, AA2e72E <AA2e...@discus sions.microsoft .comwrote:
I have a class library which contains 3 classes; one exposes all its
behaviours and the other two are used internally by the public class. My
problem is that although I can create an instance of the subservient classes,
I cannot see the methods in them from the public class.

Could someone guide me on this or give me a template?
The two subservient classes should be declared as "internal", and any
method you want to use from other classes in the same assembly should
also be declared as "internal".

Jon

Oct 4 '07 #3
Jon, I think I am still missing something. Here's the gist of the code ...
please lookout for the comments for the questions I have. Thank you very much
for your help.

The function below is the <publicclass.

public string TargetDB
{
get { return xTargetDB; }
set
{
xTargetDB = value.ToUpper() ;
switch (xTargetDB)
{
case "ORACLE":
{
TDB = new ORACLE();
break;
}
default:
{
TDB = new SQLSERVER();
break;
}
}
}
}

public string xyz()
{

// I expected test() to be exposed below but it isn't

return TDB.ToString() ; // I used ToString() just to have the
project compile

// I want to be able to run this statement: return TDB.test() ;
// HOW?
}

ORACLE and SQLSERVER are the subservient classes:

this is ORACLE.CS

sing System;
using System.Collecti ons.Generic;
using System.Text;

namespace ACM
{
internal class ORACLE
{
internal string test()
{
return "Oracle";
}
}
}

this is SQLSERVER.CS

using System;
using System.Collecti ons.Generic;
using System.Text;

namespace ACM
{
internal class SQLSERVER
{
internal string test()
{
return "SQLServer" ;
}
}
}
I am using a WindowsApplicat ion to test the class library:

namespace ACMTESTER
{
public partial class Form1 : Form
{
Main CI = new ACM.Main();
public Form1()
{
InitializeCompo nent();

}

private void Form1_Load(obje ct sender, EventArgs e)
{

}
private void button1_Click(o bject sender, EventArgs e)
{
CI.TargetDB = "ORACLE";
MessageBox.Show (CI.xyz());
}
}

Oct 4 '07 #4
On Oct 4, 3:28 pm, AA2e72E <AA2e...@discus sions.microsoft .comwrote:
Jon, I think I am still missing something. Here's the gist of the code ...
"The gist of the code" isn't terribly helpful, unfortunately. We've no
idea what TDB is, for instance - a field, a property? What's its
scope?

You've got a problem in that your SQLSERVER and ORACLE classes (it
would be good to start complying with naming conventions by the way) -
they don't implement a common interface. You should define an
interface containing the test() method, and make both classes
implement that interface. TDB should be declared to be of that
interface type, at which point your problems are likely to go away.
I'm guessing that TDB is currently declared as type object - but
unfortunately I can only guess at the moment.

Jon

Oct 4 '07 #5
Yes, TDB is declared as object.
I tried

ORACLE TDB = new ORACLE();

and SQLSERVER TDB = new SQLSERVER();

but could not get test() exposed.

Thanks for the quidance; I'll work on the 'common interface'.
Oct 4 '07 #6
On Oct 4, 4:01 pm, AA2e72E <AA2e...@discus sions.microsoft .comwrote:
Yes, TDB is declared as object.
I tried

ORACLE TDB = new ORACLE();

and SQLSERVER TDB = new SQLSERVER();

but could not get test() exposed.
Either of those would have worked in terms of exposing the test()
method, but then your TargetDB property's setter would fail, as you
wouldn't be able to assign an ORACLE reference to a variable of type
SQLSERVER or vice versa.
Thanks for the quidance; I'll work on the 'common interface'.
Righto. If you have any more problems, please post a short but
*complete* program demonstrating them. See http://pobox.com/~skeet/csharp/complete.html

Jon

Oct 4 '07 #7

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

Similar topics

20
1949
by: syd | last post by:
In my project, I've got dozens of similar classes with hundreds of description variables in each. In my illustrative example below, I have a Library class that contains a list of Nation classes. In one case, I might want a Library class with only Nations of with the continent variable "Europe", and so I'll do something like library.getContinent('Europe') which will return a Library() instance with only European nations. Similarly, I...
1
1516
by: ik | last post by:
Hello All, Please point me to the right news group if this is not the right one. I have to store c++ class hierarchy, in some structure. From that structure, I need to query for the baseclasses. I get the base class, derived class information from a text file of the form
3
1411
by: David Lozzi | last post by:
Howdy, I've discovered how to create and use a class in ASP.NET. However, when is the best time to use a class? For example, I am currently using session variables to store user information (user id, user name, full name, security level, department, etc.). Would I do better to create a class instead? Also, if I did, would I simply store the ID in the session and when accessing the class (User.FullName, User.SecurityLevel, etc.) then check the...
3
3555
by: convert a Class Library to web service | last post by:
can i convert a Class Library to be share in the internet as a web service i what thet all my classes in the Class Library will be shared
3
1637
by: eBob.com | last post by:
I have several applications which mine web sites for personal information which they publish. They publish the info in one form, I transform the info into Excel spreadsheets. So all these programs pick up name, telephone number, age, sex, etc.. And as they pick up the information they display it in text boxes. The text boxes are display only, and the info is displayed only for debugging purposes. Right now I have a lot of duplicate...
7
2111
by: WXS | last post by:
Vote for this idea if you like it here: http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=5fee280d-085e-4fe2-af35-254fbbe96ee9 ----------------------------------------------------------------------------- This is a consortium of ideas from another thread on topic ----------------------------------------------------------------------------- One of the big issues of organizing items within a class, is there are many...
5
1890
by: Sanjay | last post by:
Hi all, I am new to python. Sorry if this is too novice question, but I could not find an answer yet. While coding a business class library, I think it is preferable to have one class per source file, rather than combining all classes into one file, considering multiple developers developing the classes. So, as per my study of python, a developer using the business class
12
2090
by: Janaka Perera | last post by:
Hi All, We have done a object oriented design for a system which will create a class multiply inherited by around 1000 small and medium sized classes. I would be greatful if you can help me with the following: Can this create any problems with GNU g++ compilation, linking etc? What would be the impact to the performance of the system? Anything else we have to consider?
4
4462
by: Alan Mailer | last post by:
Again, I'm new to VB.net and there is something I need help with: Like (I assume) many of us, over time I want to be able to create some VB.net classes that I might want to use in more than one Project. So let's say I've created a Folder called "MyVBNet Classes" to hold these general-use VB.Net class files that I will eventually associate with various Projects I create. Now let's imagine I've created a class called "MyClass.vb" that...
44
2931
by: Steven D'Aprano | last post by:
I have a class which is not intended to be instantiated. Instead of using the class to creating an instance and then operate on it, I use the class directly, with classmethods. Essentially, the class is used as a function that keeps state from one call to the next. The problem is that I don't know what to call such a thing! "Abstract class" isn't right, because that implies that you should subclass the class and then instantiate the...
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8610
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,...
0
9170
Oralloy
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...
0
9031
jinu1996
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...
1
8902
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,...
0
7740
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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 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.