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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:02:52+00:00 2026-05-24T17:02:52+00:00

I have an abstract class called ChainHandler and many implementations of the ChainHandler. Other

  • 0

I have an abstract class called ChainHandler and many implementations of the ChainHandler.

Other programmers will write other implementations of that ChainHandler.

My program implements the Chain of Responsibility design pattern.

Each concrete implementation of the ChainHandler implements a handle method.

public abstract void handle(SomeclassA a);

If one handler can handle “a”, it handles it and the chain stops. If not,”a” is passed to the next Handler until it hits the end of the chain.

I want each concrete handler to have a list of all “a”s it was able to handle. But I don’t want to make the concrete classes developer to remember to write it to a list on success.

Is there a elegant way of doing it?

My best idea was the following:

1 – Change the handle method to protected at the concrete classes, make it return a boolean and change the name to innerhandle;

2 – Change the handle method at the abstract class to public and it calls the innerhandle. On success, it adds the object to the list.

  • 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-24T17:02:53+00:00Added an answer on May 24, 2026 at 5:02 pm

    The second option is surely better (and it relies on the Template method pattern) making it harder for someone implementing a subclass of doing it wrong, you can even make the handle method final so no one will ever be able to change it’s behavior and break without noticing it.

    The servlet API has such an example, the init method that takes a ServletConfig parameter can be overridden and it’s rather common to see people forgetting to call super and the original init(ServletConfig) method, so you should try to avoid this same mistake.

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

Sidebar

Related Questions

Ok so I have an abstract base class called Product, a KitItem class that
I have an abstract class, Foo, that has a non-abstract method called Bar. I
I have a class that inherits from Page, called APage. public abstract class APage:
I have an abstract class called Node . It contains a constructor that takes
I have an abstract base class called Curve . There are three classes that
Let's say I have an abstract parent class called shape, and that there are
For example, I have a class called Clothing that inherits from a abstract class
I have an abstract class called DatabaseRow that, after being derived and constructed, is
Let say I have abstract class called: Tenant and Customer. The tenant in this
I have an abstract base class called Shape from which both Circle and Rectangle

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.