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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:25:31+00:00 2026-06-08T01:25:31+00:00

I am writing an object conversion class, used to convert domain layer objects into

  • 0

I am writing an object conversion class, used to convert domain layer objects into UI objects and vice versa. The problem is that my UI objects are organized into a hierarchy and as a result my object conversion class contains “instanceof” statements. There is a definite code smell here but I’m not sure what the solution is.

So my UI hierarchy contains a RuleDTO as follows:

public class RuleDTO {
    protected long ruleID;
    protected long rowID;   
    protected AttributeDTO leftCondition;
    protected AttributeDTO rightCondition;
    protected OperationTypeDTO operationType; 
    protected boolean isActive;     
    // etc...
}

My RuleDTO can then be subclassed by AssignmentRuleDTO as follows:

public class AssignmentRuleDTO extends RuleDTO {
    protected String assignedToTeam;
    protected String assignmentOperator;        
    // etc...
}

RuleDTO can also be subclassed by EvaluationRuleDTO:

public class EvaluationRuleDTO extends RuleDTO {
    protected String successAction;
    protected String failureAction;
    // etc...
}

The problem is reached then in my ObjectConversionHelper class which contains the following type of logic:

{
    // Perform logic common to RuleDTO such as setting ruleID, isActive etc
    if(ruleDTO instanceof AssignmentRuleDTO) {
        // Set assignedToTeam and assignmentOperator etc
    }
    else if (ruleDTO instanceOf EvaluationRuleDTO) {
        // Set successAction and failureAction etc  
    }
}

What would be a good solution here instead? I’ve read about the visitor pattern, but not sure how it applies here.

Thanks

  • 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-08T01:25:32+00:00Added an answer on June 8, 2026 at 1:25 am

    Your RuleDTO class should have a method called setStuff() or something similar.

    Then you override it in AssignmentRuleDTO and in EvaluationRuleDTO to set the relevant fields.

    This way your ObjectConversionHelper can just call

    ruleDTO.setStuff();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an Object Oriented OpenGL framework in perl and I'm running into a
I'm writing an object in PHP that displays files on an FTP server. I
I am writing a fairly large C++ shared-object library, and have run into a
I am writing a bit of JavaScript that uses the Object.bind method. funcabc =
I'm writing a program for my visual basic class that computes the prices of
Does someone know library, that reduces amounts of boilerplate code when writing object proxies?
When writing a class to act as a wrapper around a heap-allocated object, I
I have the following simple methods for writing a python object to a file
I am writing code to clone object but have no cue from Hobo documentation.
I'm currently writing to methods to: read object from memory write object to memory

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.