Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8806409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:07:07+00:00 2026-06-14T02:07:07+00:00

I ran at the following dilemma: there’s no multiple inheritance in Java but I

  • 0

I ran at the following dilemma: there’s no multiple inheritance in Java but I need it, how to avoid it?

Below is the reason why I started thinking about it.

I was in need of a text box that has several specific properties and behavior (on focus and on blur events are handled). I developed DecoratedTextBox without hesitation:

public class DecoratedTextBox extends TextBox implements FocusHandler, BlurHandler {
    public void onBlur(BlurEvent event) {
        //cool feature implementation
    }

    public void onFocus(FocusEvent event) {
        //another cool feature
    }

    //other cool features
}

My GUI started looking good, but I didn’t take into account PasswordTextBox. It also must have the same properties and behaviour that DecoratedTextBox has. But PasswordTextBox is inhereted from TextBox and it is in fact another class hierarchy branch. At once I remembered that it would be great if TextArea also has all those cool properties and behavior etc.

So what is wrong with my design that it leads to thoughts about multiple-inheritance? What must be done to satisfy mentioned requirements?

Some clarification

As a result I had to inherit from PasswordTextBox, TextArea and so on to take advantage of their features (these classes are from GWT library). But I cannot understand how to weave composition here.

Update

Correct me If I understood what Anders Johansen said in a wrong way.

The solution should look like this:

public class DecoratedTextBox extend AbstractEventHandler {
    private TextBox textBox;

    //wrap TextBox methods
    public String getText() {
        return textBox.getText();
    }
}

public class DecoratedPasswordTextBox  extend AbstractEventHandler {
    private PasswordTextBox passwordTextBox;

    //wrap TextBox methods
    //...
}

public class DecoratedTextArea  extend AbstractEventHandler {
    private TextAre textArea;

    //wrap TextBox methods
    //...
}

public abstract class AbstractEventHandler implements FocusHandler, BlurHandler {
    public void onBlur(BlurEvent event) {
        //default cool feature implementation
    }

    public void onFocus(FocusEvent event) {
        //another default cool feature implementation
    }
}

updated

I tried variants suggested by Anders Johansen and Hilbrand Bouwkamp, but in each case I ran at a problem that I have a method (its signature cannot be changed) that adds widgets and one of the args is Widget itself. So if I’m not subclassing from something that is a subclass of Widget, I break a lot of classes.

Still continue thinking on solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T02:07:09+00:00Added an answer on June 14, 2026 at 2:07 am

    I can’t guesss what kind of cool features you like to add, but what about making a TextBoxBaseDecorator class, which looks something like:

    public class TextBoxBaseDecorater implements FocusHandler, BlurHandler, HasAttachHandlers {
      private final TextBoxBase textBoxBase;
      private final ArrayList<HandlerRegistration> handlers = new ArrayList<HandlerRegistration>();
    
      /*
       * Pass the TextBoxBase extending widget to be decorated.
       */
      public TextBoxBaseDecorater(TextBoxBase textBoxBase) {
        this.textBoxBase = textBoxBase;
        textBoxBase.addAttachHandler(this);
      }
    
      public void onBlur(BlurEvent event) {
        //cool feature implementation
      }
    
      public void onFocus(FocusEvent event) {
        //another cool feature
      }
    
      public void onAttachOrDetach(AttachEvent event) {
         if (event.isAttached() {
           handlers.add(textBoxBase.addBlurHandler(this));
           handlers.add(textBoxBase.addFocusHandler(this));
         } else {
           for (HandlerRegistration rh: handlers) {
              rh.removeHandler();
           }
           handlers.clear();
         }
      }
    
      //other cool features
    

    }

    You could create subclasses that create wrappers for the specific widgets, like TextBox, PasswordTextBox and TextArea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran the following code, but nothing came up on the console.... #include <stdio.h>
I ran the following comand git whatchanged 7c8358e.. --oneline and got the below output.
I am new to C++ and ran into following supposedly bug, but somehow my
I downloaded the selenium-java-2.0a5.zip http://code.google.com/p/selenium/downloads/list and ran the following code: package org.openqa.selenium.example; import org.openqa.selenium.By;
I foolishly ran the following code file.remove(list.files()) Is there any way of retrieving the
I ran the following simple query that looks like the example below: (Briefly; one
I started Solr and ran the following query: curl http://localhost:8983/solr/dataimport?command=full-import&commit=true I then checked the
I ran the following SSH commands to create my rsa key but I don't
I ran the following query, which should have had a where clause but I
I ran the following and have the devise gem included but I don't see

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.