Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

231
Views
Is it OK to inherit from an empty class?

I have an entity which has info1 or info2 dependently from its type, but only one of these infos should be filled. These infos have absolutely different properties. So my entity looks like this:

public class SomeEntity {

  private SomeEntityType type;

  private Info1 info1;  

  private Info2 info2;  

}

So my question is this Ok to create some empty abstract class Info and inherit Info1 and Info2 from it? (Since I think that the number of such Info classes can grow and I will need add all such infos to SomeEntity)


public class Info1 extends Info {
  /* some properties */ 
}

public class Info2 extends Info {
  /* some properties */ 
}

public class SomeEntity {

  private SomeEntityType type;

  private Info info;   

}
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

In a word - yes, it is. However, it may be more idiomatic to use an empty interface and have Info1 and Info2 implement it rather than extend an empty class.

over 4 years ago · Santiago Trujillo Report

0

Yes of course. That's why there is abstract class. You can create abstract class Info and write some abstract methods. You're going to implement those methods in classes Info1 and Info2.

Example

public abstract class Info {
    abstract void getInfo();
}

public class Info1 extends Info {

    void getInfo() {
        System.out.println("This is Info 1");

    }

}

public class Info2 extends Info {

    void getInfo() {
        System.out.println("This is Info 2");

    }

}

As you can see, I implemented methods differently in Info1 and Info2.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!