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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:10:53+00:00 2026-05-11T21:10:53+00:00

I have a design problem. I have two data objects which are instances of

  • 0

I have a design problem.

I have two data objects which are instances of say class A and class B.
A and B don’t have any behavior – they are java beans with getters and setters.
I have a Validation interface and 10 implementations of it defining different Validations.
I would like to specify in my properties file which Validation applies to which class.
Something like this:

class A XYZValidation,ABCValidation

class B: ABCValidation, PPPValidation, etc

How do I write my Validation class so that it serves objects that are instances of Class A OR ClassB, or just about any other Class C that I might want to add in future?

interface Validation {
public boolean check(??);
}

> Just wanted to add this line to say thank you to all those who have responded to this post and to say that I am loving my time here on this amazing website. Stackoverflow rocks!

  • 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-11T21:10:53+00:00Added an answer on May 11, 2026 at 9:10 pm

    Have you thought about using annotations to mark the fields you want to validate in your bean?

    If you have 10 different validations you could specify 10 annotations. Then mark the fields using annotations:

    @ValideStringIsCapitalCase
    private String myString;
    
    @ValidateIsNegative
    private int myInt;
    

    With reflection API iterate through all the fields and see if they are marked, something like this:

    public static <T> validateBean(T myBean) throws IllegalAccessException {
        Field[] fields = myBean.getClass().getDeclaredFields();
        // This does not take fields of superclass into account
        if (fields != null) {
            for (Field field : allFields) {
                if (field.isAnnotationPresent(ValideStringIsCapitalCase.class)) {
                    field.setAccessible(true);
                    Object value = field.get(existingEntity);
                    // Validate
                    field.setAccessible(false);
                }
            }
        }
    }
    

    An option would be to mark the whole class with the validator you want to use.

    EDIT: remember to include annotation:

    @Retention(RetentionPolicy.RUNTIME)
    

    for your annotation interface.

    EDIT2: please don’t modify the fields directly (as in the example above). Instead access their getters and setters using reflection.

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

Sidebar

Ask A Question

Stats

  • Questions 176k
  • Answers 176k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If they have an actual feed for the data, you… May 12, 2026 at 3:19 pm
  • Editorial Team
    Editorial Team added an answer For Django (Python MVC framework) try here For CSS try… May 12, 2026 at 3:19 pm
  • Editorial Team
    Editorial Team added an answer The [DefaultValue(...)] attribute is a hint to designers and code… May 12, 2026 at 3:19 pm

Related Questions

I have a couple of classes that want to pass each other some information
I'm working on creating a domain layer in Zend Framework that is separate from
I've been running into a problem where using objects from two datacontexts that are
I have a client/server application that depends on MS SQL database for backend storage,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.