Adding functionality to many classes

Discussion in 'Java' started by Melanie, Feb 23, 2005.

  1. Melanie

    Melanie Guest

    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
    Melanie, Feb 23, 2005
    #1
    1. Advertising

  2. Melanie

    SPG Guest

    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

    "Melanie" <Mel@..> wrote in message news:Xns9605AFFB86558a@63.223.5.254...
    >
    > 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
    >
    SPG, Feb 23, 2005
    #2
    1. Advertising

  3. Melanie

    Melanie Guest

    "SPG" <> wrote in
    news:O%QSd.21308$:

    > 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
    Melanie, Feb 23, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marco Ippolito
    Replies:
    0
    Views:
    2,565
    Marco Ippolito
    Oct 11, 2004
  2. =?Utf-8?B?U3R1?=

    session vars how many is to many ?

    =?Utf-8?B?U3R1?=, Mar 5, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    325
  3. dee
    Replies:
    2
    Views:
    392
  4. Christian Schlichtherle
    Replies:
    8
    Views:
    468
    John Currier
    Jul 5, 2005
  5. Tom Howard
    Replies:
    2
    Views:
    323
Loading...

Share This Page