0

Hi all,
I am pretty new to Object Oriented programming so the question i am asking might be childish..geeks, pardon me :)

alright,
i have an interface with 5 methods.
Class A is implementing that interface.
Now Class B creates an instance of Class A and calls the methods.

The functions in the Interface all have single parameter of type "Socket".
It kinda looks stupid to pass this one parameter to all the methods.
Is there any way where i can pass it just once and use it??
Please find an example below

Class A
{
Public void Func1(Socket listener)
{}
Public void Func2(Socket listener)
{}
Public void Func3(Socket listener)
{}
Public void Func4(Socket listener)
{}
Public void Func5(Socket listener)
{}
}

Class B
{
Socket server = new Socket();
A instA = new A();
instA.Func1(server);
instA.Func2(server);
instA.Func3(server);
instA.Func4(server);
instA.Func5(server);
}

Thanks in advance
-deathdarts

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by LizR
0

Well you could have a variable in Class A that you set to be your socket, eg

Class A
{
 public Socket Server;
.
.
.
.
}

Class B
{
Socket server = new Socket();
A = instA = new A();
A.Server = server;
}

but id actually question in that quick mock, why you needed server at all in class B surely it should be in class A?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.