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 8745315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:59:14+00:00 2026-06-13T11:59:14+00:00

Ive got a few instances of subclasses of View (like ImageView, ViewGroup, TextView, etc)

  • 0

Ive got a few instances of subclasses of View (like ImageView, ViewGroup, TextView, etc) , which i have them all implement two methods a() and b() and they all have to run the same init() method which is long and does the same for all of them.
how should i design my architecture to enhance code reusability in that case?

if it was C++ i could multi inherite from view and a new abstract class that runs init() on time of creation and have abstarct methods a() and b(), how is it acheived in Java?

maybe there’s some way to acheive it using some kind of a decorator?

  • 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-13T11:59:15+00:00Added an answer on June 13, 2026 at 11:59 am

    If I understand you correctly, you can create an abstract class AbstractView that extends View and implements your common init() method. AbstractView should declare the abstract methods a() and b(), but leave the implementations to the subclasses.

    public abstract class AbstractView extends View {
        public void init() {
            // common init implementation here
        }
    
        public abstract void a();
        public abstract void b();
    }
    

    Since you’re trying to add behavior to a group of existing subclasses (ImageView, ViewGroup, TextView, etc.), you probably do need to create a wrapper for each subclass (MyImageView, MyViewGroup, MyTextView, etc.). Each of these subclasses would extend AbstractView and implement their own a() and b() methods, but inherit the common init() method (along with all of the methods implemented in the View class. You can then create delegate methods for the exising behavior in ImageView, ViewGroup, TextView, etc. that you need to keep unchanged.

    public class MyImageView extends AbstractView {
    
        private ImageView wrappedImageView;
    
        public MyImageView(Context context) {
            wrappedImageView = new ImageView(context);
        }
    
        // TODO: Implement other constructor wrappers
    
        final void clearColorFilter() {
            wrappedImageView.clearColorFilter();
        }
    
        // TODO: Implement other method wrappers
    
        @Override
        public void a() {
            // specific implementation here
        }
    
        @Override
        public void b() {
            // specific implementation here
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a few queries (20+) which all return the following three columns: Building
I've got a few classes in lib/ which are not reloadable (due to their
I've got a few files that have been serialized by directly writing C++ struct
I've got quite a few SQL statements like such: SELECT foo FROM things WHERE
I've got a few apps that I'd like to go back and retroactively build
So I've got a solution that contains a few big projects, which I'm trying
I've got entity, which has @EmbeddedId. In the id class there are a few
I've got a few instances where some duplicate records were created and now I
I've got a few controllers here at work that contain methods I can use
I've got a few loading bars that appear during any postbacks. How can I

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.