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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:48:43+00:00 2026-06-06T05:48:43+00:00

I have a class called Property which has nothing but get -methods. All the

  • 0

I have a class called Property which has nothing but get-methods. All the fields will be set when a new instance of Propertyis created. Property implements an interface called IProperty.

Due to some bug in a library I use, I have to set the name of an instance of Property anew after its creation. Therefore it was suggested to create a WrapperPropertyclass that will provide a public setName-method which itself calls a therefore created setName()-method in Property, which will be protected/package view.

The problem is that I cannot make this method protected in Property, because Eclipse tells me to add it to the interface IProperty and make it public.

Is there some work-around to it?

WrapperIProperty:

public class WrapperIProperty {

    private IProperty prop;

    WrapperIProperty(Property prop) {
        this.prop = prop;
    }

    public void setName(String name) {
        prop.setName(name);
    }
}

Property:

public class Property implements IProperty {

    String name;

    protected void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }
    public int getFoobar() {
        return 123;
    }
    public int getWhatever() {
        return 987;
    }
}

IProperty:

public interface IProperty {

    public int getWhatever();
    public int getFoobar();
    public String getName();

}

This is how it looks at the moment. Obviously it won’t work, since I cannot let the method be protected in the Property class. Therefore I best get rid of the interfacee entry somehow. But how?

  • 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-06T05:48:45+00:00Added an answer on June 6, 2026 at 5:48 am

    What you probably want to do is to leave the IProperty interface alone (don’t add the setName method to it) and create a delegating wrapper class which provides the method you want (wraps an implementation of the interface).

    This way you can feed wrapped properties and regular properties to whatever needs them.

    public class WrappedProperty implements IProperty {
    
        private String name;
    
        private Property prop;
    
        WrappedProperty (Property prop) {
            this.prop = prop;
        }
    
        protected void setName(String name) {
            this.name = name;
        }
        public int getWhatever() {
            return prop.getWhatever();
        }
        public int getFoobar() {
            return prop.getFoobar();
        }    
        public String getName() {
            if (this.name == null) {
               return prop.getName():
            } else {
                return this.name; 
            }
        }
    }
    
    public class Property implements IProperty {        
    
        public String getName() {
            return "blah";
        }
        public int getFoobar() {
            return 123;
        }
        public int getWhatever() {
            return 987;
        }
    }
    
    public interface IProperty {
    
        public int getWhatever();
        public int getFoobar();
        public String getName();
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base class with a property called Name, which has an XmlText
I have a User class that has a property called Creator which is of
I have a class called Item. Item has an identifier property called ItemCode which
I have a class with a Property called 'Value' which is of type Object.
I have a class called Question that has a property called Type. Based on
I have a class TxRx with a property called Common. Common then has a
I have a Menu class that has a IQueryable property called WebPages. In the
I have an abstract class named PersonAbstract . It has an abstract property called
I have a class, called DateField , that has a string Value property. If
I have a ViewController class that has a property that is the model which

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.