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

  • Home
  • SEARCH
  • 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 8769783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:25:40+00:00 2026-06-13T17:25:40+00:00

My dilema is in creating one method that follows the builder pattern, which sets

  • 0

My dilema is in creating one method that follows the builder pattern, which sets a variable and returns itself, but I have an interface Visitor which is implemented by BasicVisitor and that is extended by other visitor implementations.

Furthermore, I have a Visitable interface, which is implemented by SampleVisitable and that has methods that keep a history of all visitors that have visited.


So the problem is that I want to only keep a full reference of the visitor in the history of SampleVisitable if that visitor is “important”, since the host calls Visitor.clean() before the visitor visits, which cleans all the data from the last visit, but I want the “important” visitors’ data to remain in the history.

This is what I have so far for the implementation:

public interface Visitor {
    public void visit( Visitable visitable );

    public Visitor clone();

    public <V extends Visitor> V important();

    public boolean isImportant();
}

This is a snippet from the SampleVisitable class:

public void accept( Visitor visitor ) {
    visitor.clean();
    visitor.visit( this );
    addToHistory( visitor ); // only adds if visitor.isImportant() == true
}

Then I have BasicVisitor which implements the important() method. Now I don’t want to have to override the important() method every time, but with my implementation I would have to, since any other visitors would have an error of the form “cannot convert from BasicVisitor to [OtherVisitor]” if they use the important() method without overriding it:

OtherVisitor otherVisitor = new OtherVisitor().important(); // cannot convert from BasicVisitor to OtherVisitor error.

What is the best way to do this? I need to have this feature implemented once, and available for use by all other sub-classes, without requiring them to override it. Thank you!

Edit:

Wow, abstract classes are exactly what I was looking for! I did some more research and found this post on differences between interfaces and abstract classes, and I hope it helps others looking for an answer.

After I posted this answer I realized that I didn’t have to use the builder pattern in this situation, I could have just created a setImportant( boolean isImportant ) and would have basically what I needed, but I’m glad I asked anyways, because this is what I needed for another design issue.

Edit2:

After trying the abstract class, my main problem is still there, I still have to override the important() method for each sub-class of Visitor.

Ilya

  • 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-13T17:25:41+00:00Added an answer on June 13, 2026 at 5:25 pm

    Please try this. If you use an abstract class, then the method that you implement will be available for all sub-classes.

    public abstract class Visitor {
        public abstract void visit( Visitable visitable );
    
        public abstract Visitor clone();
    
        public abstract <V extends Visitor> V important();
    
        public boolean isImportant() {
            //logic to store important visitors
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got a designing dilema. I have a class named UserAccount that represent
I have a weird dilema that I can't seem to place a finger on
I'm creating a program which follows certain rules to result in a count of
I am creating a class that implements the composite pattern; the class is supposed
Im in a dilema on which one of these methods are most efficient. Suppose
Ok need some help, I have a system I'm creating that will allow users
Here's my dilema. I have a box which is 315x210px, and a bunch of
I have a dilema, I want to present to the user a semi-transparent view.
I have an interesting dilemma to which, I hope, someone may have an answer.
I have the following dilema: My clients (mom-n-pop pawnshops) have been using my mgmt.

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.