Connecting Tech Pros Worldwide Forums | Help | Site Map

OOP help needed

Bilo
Guest
 
Posts: n/a
#1: Nov 16 '05
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?



Jeff Louie
Guest
 
Posts: n/a
#2: Nov 16 '05

re: OOP help needed


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[color=blue]
>but how can I make it in class C without making a new object of B?<[/color]


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Eddie Pazz
Guest
 
Posts: n/a
#3: Nov 16 '05

re: OOP help needed


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(); }
};

"Bilo" <justler123@yahoo.com> wrote in message
news:O%23sYqvLLEHA.1416@TK2MSFTNGP09.phx.gbl...[color=blue]
> 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?
>
>[/color]


Bilo
Guest
 
Posts: n/a
#4: Nov 16 '05

re: OOP help needed


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.

"Eddie Pazz" <drpazz@hotmail.com> schrieb im Newsbeitrag
news:ejOzlVOLEHA.2976@TK2MSFTNGP10.phx.gbl...[color=blue]
> I'm not sure if I got what you're looking for. But I take it that you want[/color]
C[color=blue]
> to call a method in B? If so, pass C a reference to B when created so C[/color]
can[color=blue]
> 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(); }
> };
>
> "Bilo" <justler123@yahoo.com> wrote in message
> news:O%23sYqvLLEHA.1416@TK2MSFTNGP09.phx.gbl...[color=green]
> > 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[/color][/color]
and[color=blue][color=green]
> > mouse is up then
> >
> > B must do his method method1() . I dont want to make the method1()[/color][/color]
static[color=blue][color=green]
> > because than nearly everything becomes static
> >
> > but how can I make it in class C without making a new object of B?
> >
> >[/color]
>
>[/color]


Closed Thread