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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:27:50+00:00 2026-05-27T02:27:50+00:00

I have got a problem and a solution, but I am not really satisfied

  • 0

I have got a problem and a solution, but I am not really satisfied with it:

My problem:

I have got several classes and several “properties”. These properties are not described by a method or a logical value. They are defined by those classes, which own a property (common features).
Now there should be formed groups of classes with the same properties. These groups can be interpreted as sets.
The properties of sub-groups (subsets) do not necessarily have to do with the properties of the parent group (superset).
In addition, the compiler can check for these groups on type-correctness.

Previous solution:

For each group, a (possibly empty) interface is created. All classes with a common property implement this interface. The group and the interface is so for all classes with this property.
If we now pass a parameter to a method that should only take classes with a certain property, then the parameter type is the corresponding interface.

Description of an example:

All classes implement an interface with a method m1.
For each property, an interface is created, which is implemented by all classes that meet the appropriate property. Properties can for example be side effects that occur when running this method.
The interface is therefore a set of classes with a corresponding property. It represents the property so to speak.
Furthermore, there is another method m2, which receives as a parameter an object of a certain group of property. In m2, m1 from the given object is called. Thus we know about the side effects, which occur when running m1, or a property, which is met. It is not possible to pass m2 an object with no corresponding property/side effect, because the compiler checks for type correctness.

Code-Example:

(Side effects are presented through an output)

public class Example {
    public static void m2(Property_12 p_12) {
        p_12.m1();
    }

    public static void main() {
        Class_1 c_1 = new Class_1();
        Class_2 c_2 = new Class_2();
        Class_3 c_3 = new Class_3();

        m2(c_1);
        m2(c_2);
        // m2(c_3); // Is not passed by the compiler (wrong type)
    }
}

interface Combinable {
    public void m1();
}

interface Property_12 extends Combinable {}
interface Property_13 extends Combinable {}
interface Property_23 extends Combinable {}
interface Property_123 extends Combinable {}

class Class_1 implements Property_12, Property_13, Property_123 {
    @Override
    public void m1() {
        System.out.println("Property (1,2)");
        System.out.println("Property (1,3)");
        System.out.println("Property (1,2,3)");
    }
}

class Class_2 implements Combinable, Property_12, Property_23, Property_123 {
    @Override
    public void m1() {
        System.out.println("Property (1,2)");
        System.out.println("Property (2,3)");
        System.out.println("Property (1,2,3)");
    }
}

class Class_3 implements Combinable, Property_13, Property_23, Property_123 {
    @Override
    public void m1() {
        System.out.println("Property (1,3)");
        System.out.println("Property (2,3)");
        System.out.println("Property (1,2,3)");
    }
}

Why I am not satisfied with this solution?

My concern is not to a specific case, but a general problem.
The number of interfaces that you create quickly shoots in the air:

  • possible combinations = power set of the set of all classes
  • |P(C)| = 2^|C|

If the interfaces/groups are set up as in this case, according to a specific system,
there must be a way to solve the whole thing more elegant than to write an interface for each group. The effort to create 2^|C| interfaces is already enormous and it should be possible to reduce it at least.
If you now want to summarize several properties, you are once again facing the same problem. Thus you would have to create any combination of interfaces for an interface:

  • |P(P(C))| = 2^2^|C|

If you handle the huge amount of writing, you can after all pass objects with multiple properties.

I hope my wording is fairly clear and there will be one or the other interesting proposal.

Thank you for your efforts!


There are always 2^|C| interfaces. Maybe I can use a code-generator to creat these interfaces. What do you think of this idea?


C = The set of all classes that are to be grouped.


It is important that every class has something in common with one, two, …, and |C|-1 others, so that each possible “combination of classes” (=grouping) exists.
Furthermore, no set may appear twice. It follows that the set of all groupings is the power set. My properties are these groupings.


You can ignore the one-element sets (and the empty set), since it is already the class itself. Thus the formula is actually:

|P(C) \ ({ {x} : x in C } add "empty set")| = |P(C)| - |C| - 1 = 2^|C| - |C| - 1

Example:
|C| = 2 => |P(C)| – |C| – 1 = 2^|C| – |C| – 1 = 2^2 – 2 – 1 = 4 – 2 – 1 = 1 (= groupings/interfaces)

Class_1 --|
          |--> P_12
Class_2 --|

Example:
|C| = 3 => |P(C)| – |C| – 1 = 2^|C| – |C| – 1 = 2^3 – 3 – 1 = 8 – 3 – 1 = 4 (= groupings/interfaces)

       |-- Class_1 --|
       |             |-- P_12 --|
       |   Class_2 --|          |-- P_123
P_13 --|      |______           |
   |   |             |-- P_23 --|
   |   |-- Class_3 --|          |
   |____________________________|

A concrete example:

          |-- PolarBear --|
          |               |--> White --|
          |   Swan -------|            |--> Animal
Mammal <--|     |_________             |
   |      |               |--> Fly ----|
   |      |-- Bat --------|            |
   |___________________________________|

Code:

public class AnimalsWithProperties {

    // It can be passed only white mammal.
    public static void whiteAnimal(White w) {
        w.shout();
    }

    // All animal can be passed
    public static void animalShout(Animal a) {
        a.shout();
    }

    public static void main(String[] args) {
        PolarBear e = new PolarBear();
        Swan s = new Swan();
        Bat f = new Bat();

        whiteAnimal(e);
        whiteAnimal(s);
        // whiteAnimal(f); // Error
        animalShout(e);
        animalShout(s);
        animalShout(f);
    }

}

interface HasAnimalProperty {
    public void shout();
}

interface White extends Animal {}
interface Fly extends Animal {}
interface Mammal extends Animal {}
interface Animal extends HasAnimalProperty {}

class PolarBear implements White, Mammal {
    @Override
    public void shout() {
        System.out.println("PolarBear: I am a white Mammal.");
    }
}

class Swan implements White, Fly {
    @Override
    public void shout() {
        System.out.println("Swan: I am white and can fly.");
    }
}

class Bat implements Fly, Mammal {
    @Override
    public void shout() {
        System.out.println("Bat: I am a flying mammal.");
    }
}
  • 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-05-27T02:27:51+00:00Added an answer on May 27, 2026 at 2:27 am

    If you want to treat these properties as interfaces, I would strongly consider looking at finding a way to automatically generate the classes and/or interfaces.

    I would personally take a look at Clojure’s methods for generating interfaces and classes, which would quite literally allow you to pass a list of strings to generate the interfaces for. You could then easily package the resulting set of classes into a jar and use it for the rest of your project, which could be written in Java (or Clojure for that manner). Automatically generating the power set of possibly classes would also be relatively simple.

    Another possibility which fits with the above is using a byte code generator to generate the interfaces and classes, though I think it would be simpler to use the above.

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

Sidebar

Related Questions

I've got a problem I can't find any solution for. I have a textfile
I've got a problem I'm not sure how best to solve. I have an
I have got a really bad memory leak I am trying to fix, but
I have got a problem with calling a global function, which takes a pointer
I have got the following problem since the server has safe mode turned on,
I have got a strange problem about in_array recently which I cannot understand. e.g.
I have got a performance problem about TextField.htmlText +=msg .And I know that TextField.appendText(msg)
I've got a problem where I have a .co.uk domain of which I am
Got a problem with a query I'm trying to write. I have a table
Okay, so I've got a problem - and I'd love to have it fixed.

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.