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

The Archive Base Latest Questions

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

I’ve just come across a pattern I’ve seen before, and wanted to get opinions

  • 0

I’ve just come across a pattern I’ve seen before, and wanted to get opinions on it. The code in question involves an interface like this:

public interface MyCrazyAnalyzer {     public void setOptions(AnalyzerOptions options);     public void setText(String text);     public void initialize();     public int getOccurances(String query); } 

And the expected usage is like this:

MyCrazyAnalyzer crazy = AnalyzerFactory.getAnalyzer(); crazy.setOptions(true); crazy.initialize(); Map<String, Integer> results = new HashMap<String, Integer>(); for(String item : items) {     crazy.setText(item);     results.put(item, crazy.getOccurances); } 

There’s reasons for some of this. The setText(…) and getOccurances(…) are there because there are multiple queries you might want to do after doing the same expensive analysis on the data, but this can be refactored to a result class.

Why I think this is so bad: the implementation is storing state in a way that isn’t clearly indicated by the interface. I’ve also seen something similar involving an interface that required to call ‘prepareResult’, then ‘getResult’. Now, I can think of well designed code that employs some of these features. Hadoop Mapper interface extends JobConfigurable and Closeable, but I see a big difference because it’s a framework that uses user code implementing those interfaces, versus a service that could have multiple implementations. I suppose anything related to including a ‘close’ method that must be called is justified, since there isn’t any other reasonable way to do it. In some cases, like JDBC, this is a consequence of a leaky abstraction, but in the two pieces of code I’m thinking of, it’s pretty clearly a consequence of programmers hastily adding an interface to a spaghetti code class to clean it up.

My questions are:

  1. Does everyone agree this is a poorly designed interface?
  2. Is this a described anti-pattern?
  3. Does this kind of initialization ever belong in an interface?
  4. Does this only seem wrong to me because I have a preference for functional style and immutability?

If this is common enough to deserve a name, I suggest the ‘Secret Handshake’ anti-pattern for an interface that forces you to call multiple methods in a particular order when the interface isn’t inherently stateful (like a Collection).

  • 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. 2026-05-11T15:10:34+00:00Added an answer on May 11, 2026 at 3:10 pm

    Yes, it’s an anti-pattern: Sequential coupling.

    I’d refactor into Options – passed to the factory, and Results, returned from an analyseText() method.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have some data like this: 1 2 3 4 5 9 2 6

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.