Adding functionality to many classes

M

Melanie

I have lots of UI classes derived from different base classes.

I'd like to be able to add functionality to all these classes such as 'F1
key opens help', 'Escape key dismisses', or 'all exceptions write to a
particular file'.

I'd like to do this without repeating the code over every base class every
time I get a new requirement.
In C++ I could have used multiple inheritance. What do I do in Java?

-Melanie
 
S

SPG

Hi,

If they all have different base classes then I would do this..

Creat an interface that they all implement to handle the keyPress event you
want.
Create a class that can handle the keypress in the way you want.
In each of your classes, create an instance of this new handler class, and
delegate the event down to the handler class.

Java doe snot have multiple inheritance... Which is a shame...

Steve
 
M

Melanie

Hi,

If they all have different base classes then I would do this..

Creat an interface that they all implement to handle the keyPress
event you want.
Create a class that can handle the keypress in the way you want.
In each of your classes, create an instance of this new handler class,
and delegate the event down to the handler class.

Java doe snot have multiple inheritance... Which is a shame...

Steve

Ahh, of course.

Thanks Steve!

-Mel
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top