473,473 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Calling a variable class name

Look this code, well, you know how it works, in "public server (client cl)
{ cl.Write(); }" "client" is a know class name, but if somebody write a
custom start class (like client) and it call to "server" the type of the
start class can be change (ie public class client"s")

At this instance, how can i pass the class client to server if the name
(better type) of the parent is unknow?

public class client : Windows.Forms.Form {
public client{ new server(this); }
public Write { System.Console.Write("HI"); }
}

public class server {
public server (client cl) { cl.Write(); }
// public server (can_be_any_name cl) { cl.Write(); }
}
Nov 16 '05 #1
1 1467
Hi smeagol:

One approach to take is to design a base class or interface from which
all client classes must derive. Then the server code does not need to
know what the name of the type is you are passing in, it only needs to
know that whatever type comes in will be derived from the base class
you designed, or implement the interface you provided.

For example, with an interface, define the interface all client's must
support:

public interface IClient
{
void Write();
}

The server will require an object implmenting IClient:

public class Server
{
public Server (IClient client) { client.Write(); }
}

Whoever writes a client must implement the interface:

class FooClient : IClient
{
public void Write()
{
// this is one implementation
}
}

class BarClient : IClient
{
public void Write()
{
// this is another implementation..
}
}

This should achieve what you need to do. As for deciding between using
an interface versus a base class, you can search for "When to Use
Interfaces" on MSDN.

HTH,

--
Scott
http://www.OdeToCode.com/
On Sat, 2 Oct 2004 18:45:17 -0300, "smeagol" <pedorro77.hotmail.com>
wrote:
Look this code, well, you know how it works, in "public server (client cl)
{ cl.Write(); }" "client" is a know class name, but if somebody write a
custom start class (like client) and it call to "server" the type of the
start class can be change (ie public class client"s")

At this instance, how can i pass the class client to server if the name
(better type) of the parent is unknow?

public class client : Windows.Forms.Form {
public client{ new server(this); }
public Write { System.Console.Write("HI"); }
}

public class server {
public server (client cl) { cl.Write(); }
// public server (can_be_any_name cl) { cl.Write(); }
}


Nov 16 '05 #2

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

Similar topics

23
by: stewart.midwinter | last post by:
No doubt I've overlooked something obvious, but here goes: Let's say I assign a value to a var, e.g.: myPlace = 'right here' myTime = 'right now' Now let's say I want to print out the two...
7
by: Klaus Johannes Rusch | last post by:
Is the following code valid and supported by current implementations? function somename() { this.show = function () { document.write("somename called") } } var somename = new somename();...
7
by: ~toki | last post by:
Having this: public class MyClass : UserControls { public int number=25; public MyClass { new TestClass(this); } }
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
12
by: st_ev_fe | last post by:
I've noticed that when constructing a subclass, the base class get's it's contructors called. Is there some way to avoid this? The base class has one variable, which gets initialised to 0. ...
2
by: John Salerno | last post by:
I'm reading about class methods now and I have a question about calling them. I know it is wrong of me to assume it needs to work in a parallel manner to an instance method, but I'm curious why it...
2
by: Rafe Culpin | last post by:
Does anyone please know of a way to access static methods of a class, when the name of that class is held in a variable? I have several classes (PHP5) which all have identically named methods and...
7
by: TkNeo | last post by:
I don't know the exact terminology in python, but this is something i am trying to do i have 3 functions lets say FA(param1,param2) FB(param1,param2) FC(param1,param2) temp = "B" #something...
3
by: Matthew Keene | last post by:
I would like to be able to call a specific classmethod on a class name that is going to be passed from another parameter. In other words, I have a call that looks something like: x = Foo.bar()...
0
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...
0
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,...
0
tracyyun
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...
0
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,...
1
isladogs
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
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...

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.