OOP help needed

  • Thread starter Thread starter Bilo
  • Start date Start date
B

Bilo

Hi,
I have 3 classes
A , B ,C
A makes an object of B with
B b = new B();

B makes an object ob C with
C c= new C();

A and C are WindowsForms

in C i have a listbox with a MouseUp event. when something is selected and
mouse is up then

B must do his method method1() . I dont want to make the method1() static
because than nearly everything becomes static

but how can I make it in class C without making a new object of B?
 
You could create an object that coordinates interactions between
widgets.
This "mediator" object is an intermediary that keeps widgets from
referring to
each other explicitly. Widgets know, and signal, the mediator and the
mediator contains the logic to update the widgets as needed.

The lazy way is for B to register an interest in C c.addNotify(b).

Regards,
Jeff
 
I'm not sure if I got what you're looking for. But I take it that you want C
to call a method in B? If so, pass C a reference to B when created so C can
call it

class B {
public test();

public createC() {
C c = new C(this);
}

in C:

class C {
private B b;

C ( B b ) { this.b = b; }

listBox1_MouseUp(...) { this.b.test(); }
};
 
Thx,
your codes makes an error because it try to convert object B to a Object C
and that makes an error.
But it help me . Hasnt the idea to send B with the constructor of class C.
Thx solved my problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top