Class Action

  • Thread starter Thread starter pigeonrandle
  • Start date Start date
P

pigeonrandle

Hi,
Funnily enough, i have a question about passing data between classes.
There's an excellent diagram below to help drive away any confusion.

I have class A which contains an instance of class B and class E.
Class B contains an instance of class C.

What is the best way to move an object (class D) created in class C to
class E?!

A
{
...B
{
.....C
{
.......D (from inside class C)
}
}
...E
{
..... (to inside class E)
}
}

I am currently raising a chain of events in the classes with class D as
part of the EventArgs. This seems like a rather contrived method so any
adivice you have will be greatfully received.

Cheers,
James Randle.
 
pigeonrandle said:
Hi,
Funnily enough, i have a question about passing data between classes.
There's an excellent diagram below to help drive away any confusion.

I have class A which contains an instance of class B and class E.
Class B contains an instance of class C.

What is the best way to move an object (class D) created in class C to
class E?!

A
{
..B
{
....C
{
......D (from inside class C)
}
}
..E
{
.... (to inside class E)
}
}

You say that class A contains an INSTANCE of B and E which looks like
this:

public class A
{
private B b;
private E e;
...
}

but your pseudocode looks more like classes B and E are nested classes
inside A.
public class A
{
// other A stuff
...

public class B
{
// other B stuff
...
}
public class E
{
// other E stuff
...
}
}

Depending on which it is there is a different answer.

A small demo program that demonstrates your problem could held as well

Bill
 
Bill,
Sorry. None of them are actually textually nested inside each other,
the classes contain objects of the 'nested' classes.

Cheers,
James.
 
Hi ,

You will have to pass a reference of E to B which will pass it over to C.

Can you give a little more detail about the creation time of all the
instances?
 
Ignacio,
Thanks for replying!

It's a little more complicated than my first explanation, but here is
an attempt at a 'better' one.

Class A is a server class that contains class B (a TCP server class),
which in turn contains class C (a TCP client handler class) that is
launched in a separate thread when a connection is made.

Class B is also sat on a different thread to class A.

Class E runs on it's own thread, and is responsible for processing
objects of type Class D that are put into it's queue by class C.

Funnily enough, i have actually already done what you suggested, and as
i add items to the queue using lock(Queue) i assume it will be thread
safe...

Cheers,
James.
 
Back
Top