class design need help

H

HS1

Hello all

I have 3 classes with dependency relationship as following:

ClassA depends on ClassB. e.g. when I click a button in a PanelA (an object
presenting for ClassA), a new PanelB (presenting for ClassB) will be shown.

ClassB depends on ClassC. e.g. when I click a button in the Panel B, a new
PanelC will be shown (presenting for ClassC)

ClassA --> ClassB --> ClassC

What I want is that after I click a button OK in PanelC, the content of this
panel will be updated(or presented) in PanelA (the PanelC will be closed).

Could you please help me to choose a suitable class design. Do I need to
have a variable of ClassA in ClassC to update the value in ClassA. What
about ClassB.

Thank you...

S.H1
 
C

Chris Smith

HS1 said:
I have 3 classes with dependency relationship as following:

ClassA depends on ClassB. e.g. when I click a button in a PanelA (an object
presenting for ClassA), a new PanelB (presenting for ClassB) will be shown.

ClassB depends on ClassC. e.g. when I click a button in the Panel B, a new
PanelC will be shown (presenting for ClassC)

ClassA --> ClassB --> ClassC

What I want is that after I click a button OK in PanelC, the content of this
panel will be updated(or presented) in PanelA (the PanelC will be closed).

Could you please help me to choose a suitable class design. Do I need to
have a variable of ClassA in ClassC to update the value in ClassA. What
about ClassB.

Is this a Swing application? If so, there is already a design common to
the entire Swing architecture that you should use. Even if not, you
probably still want to follow the same pattern.

Specifically, you want a class to encapsulate the data that's displayed
by PanelA and modified by PanelC. That class should contain an event
listener setup to notify others of when it's changed. When you interact
with (however indirectly) PanelC from PanelA, you need to let PanelC
know about this common data model somehow. The change that PanelC makes
to the model will cause PanelA to be notified by the event listener, and
PanelA will update itself.

For examples, look at pretty much any Swing class whose name ends with
the word "Model". Specifically, pay attention to methods called
addXXXListener, for any value of XXX, and the supporting classes and
interfaces.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
H

HS1

Thank you
However, it is not swing and I am still confused. I will try following your
suggestion: "That class should contain an event listener setup to notify
others of when it's changed"
 
C

Chris Smith

HS1 said:
However, it is not swing and I am still confused. I will try following your
suggestion: "That class should contain an event listener setup to notify
others of when it's changed"

Please give more information about your problem and environment. Your
being so vague about the application is not helping the matter.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
F

FISH

HS1 said:
Thank you
However, it is not swing and I am still confused. I will try following your
suggestion: "That class should contain an event listener setup to notify
others of when it's changed"


Events are used when objects need to when know particular circumstances
have occured in another object. These objects (the listeners) register
themselves with the object they wish to monitor (the event source). When
something happens in the event source object it calls a method on each of
the listeners to inform them. You'll probably recognise this as exactly
how AWT and Swing handle events.

In your example A needs to know when C has done 'something'. So you
need to create a listener interface to describe this event, and an
event object which contains all the data you want to pass from C to A
when the event happens. A implements your interface, and registers
itself with C via an addXXXListener type method (which you need to
write). C will remember A, and when 'something' happens it builds an
event object and calls the listener interface method, passing over
the event. (Just like a button in AWT calls actionPerformed and
passes over an ActionEvent object when pressed.)

For more info, try Googling for Java examples and tutorials on AWT
(or Swing) and events.


-FISH- ><>
 

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

Members online

Forum statistics

Threads
474,201
Messages
2,571,052
Members
47,656
Latest member
rickwatson

Latest Threads

Top