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

The Archive Base Latest Questions

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

I have created a rather complicated piece of (Java) code for a game I

  • 0

I have created a rather complicated piece of (Java) code for a game I am working on. I’m fairly sure I will need to change it in the future to optimize or otherwise change the exact functioning. The code can efficiently loop through a subset of the game entities.

The problem is that while looping over this subset different codes should be executed. For example:

  • The first found game entity should be returned
  • A boolean value is to be returned when a game entity matches certain criteria (several criteria possible).

    There are several simple solutions possible:

  • Copy the code some times and in each copy change the code that is responsible for the specific needs. I prefer not to do this as future changes in the code will have to be updated at three different times. Besides that, it will make an unnecessarily mess of things. However, it does seem to be the solution that results in the most “efficient” code.
  • Check what specific need it requires using if statements. I prefer not to do this as it results in code that checks for things that are not necessary.
  • Build a collection of the game entities while looping of the subset and afterward supply this collection for methods that take care of the specific needs. I prefer not to do this as the code builds things that do not need building. I am favoring this solution.

    As one can see, both efficient and easily manageable code is required. Are there any other solutions possible with the Java programming language? I would prefer to supply the code with a pointer of some sort to the method that takes care of the specific needs but I do not know how or if that is possible in Java.

    Besides the hope for a neat solution, I ask this because I want to learn every in and out of Java! Thanks for any answers!

    Cheers,
    Armored

    • 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-16T15:24:12+00:00Added an answer on May 16, 2026 at 3:24 pm

      Declare an interface with methods that the looping code calls, then supply the looping code with different implementations of the interface depending on what you need it do to.

      This is commonly referred to as the Template Method Pattern

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

    Sidebar

    Related Questions

    I have a rather complicated Binding situation. I have a solution that I created
    I have a rather complicated (and customized) Entity Framework entity class library created, and
    I have created some JQuery that will expand a div 'popup' on hover and
    I have a rather complicated toolchain so prepare for a lengthy post until getting
    I have been using django to write a rather complicated object-oriented model for a
    I have created a rather simple photo gallery that I wish to apply PayPal
    I have a rather complicated scenario that I have never really had to deal
    I have a rather massive number of threads being created inside a clojure program:
    I have a rather complicated query on my PostgreSQL database spanning 4 tables via
    I have a set of dynamically created svg objects. Some of them have rather

    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.