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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:23:20+00:00 2026-05-28T17:23:20+00:00

I’m sure this is something that comes up regularly, but I don’t know how

  • 0

I’m sure this is something that comes up regularly, but I don’t know how to handle it, nor do I know the relevant terms to search for. I’m creating a utility for a search engine which appends “heuristics” to incoming search jobs using Java. (So, for instance, if a user searches for “couch”, the utility will append terms like “sofa” and “bedroom furniture” to provide more relevant results.)

I’m having a bit of trouble handling the global information. In this specific case, the heuristic terms are the global information that can be modified by somebody working on the backend, or can be accessed by a client using the search. So, I wanted to know what would be the best practices in this case: I can create a class with almost purely static methods called something like HeuristicSearchEngine, which can be launched in the beginning of the server startup, load the heuristics into memory, and have methods which can be used to access the heuristics for the search or modify the terms. This just seems sloppy, since it doesn’t use any of the advantages of OOP. So, another approach is to use a singleton to create an instance of the current heuristics. That way, whenever a search job is launched, the job can load the instance of the current state, append heuristics to the search and move on. However, the singleton didn’t seem appropriate here, and I’d like to know how others would handle this case.

Let me know if you’d like further clarification any other info.

  • 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-28T17:23:22+00:00Added an answer on May 28, 2026 at 5:23 pm

    The singleton/factory method you are describing is functional and easy to implement. But singletons are dangerous because should you want to implement variants to your herustics services down the road, you may have to refactor things to accommodate them. Furthermore, singletons are typically passed around with static factories which, themselves, can interfere with extendability.

    Instead of a singleton/factor approach, consider dependency injection. It’s more cumbersome to implement but extends more gracefully.

    With dependency injection, you anticipate components’ needs for data/services, passing them to dependent components before they need them. (Whereas the alternative is leaving the work of finding that data/service to that component – functionality you might achieve with something like a static factory.) In general, you de-couple components and isolate their functionality; doing this is generally accepted as an effective design approach.

    As a more concrete example, instead of your servlets calling com.me.Herusitic#getInstance(), they would instead have an instance of Heuristic passed to their constructors. That Heuristic reference is saved within the object and is called upon as needed. Later on, when you’ve extended Heuristic into FancyHeuristic and FakeHeuristicForTesting and you want your servlets to use them instead, you don’t need to modify your servlet code: just pass in the new type of heuristic. With the factory approach, you’d have to rewrite your factory logic.

    This answer only scratches the surface of this topic. Fortunately, there is no end to discussion on the DI design pattern (both on StackOverflow and elsewhere), so I’ll leave it to you to continue research.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,

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.