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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:06:05+00:00 2026-05-22T23:06:05+00:00

My code is starting to look out of control so I thought I would

  • 0

My code is starting to look out of control so I thought I would ask for help.

I have an enum class that implements an interface. The first thing the method does is get a db connection from a pool using jndi. Then based on the objects properties performs a series of calculations and returns a result.

public interace MyInterface {  
     public ResultObject calculate(MyObject myObject); 

}

public enum MyEnum implements Myinterface {
    public ResultObject calculate(MyObject myObject) {
         //several steps
    }
}

This has been working fine with only one calculation. I now have a few more ways to calculate with just a few changes needed for each calculation.

The template method design pattern sounds perfect for this but I am confused on how I can make it work with the enum implementation I currently have? I don’t want to add a bunch of branch statements in my enum calculate method and make it hard to maintain.

I am using spring mvc and I have a controller for each calculation that extends a base class. I call super.calculate() in each controller and I would like to keep this the same.

Does anyone have any suggestions for this scenerio? I feel like when I started the design was good but now I am not so sure.

  • 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-22T23:06:06+00:00Added an answer on May 22, 2026 at 11:06 pm

    I find it really confusing that you would have an enum that implements an interface like this, especially if the enum is responsible for interacting with a database – sounds like you may be misusing enums.

    As for the actual problem, I would create a base class (potentially abstract) which contains the core logic of the calculate(MyObject) method and delegates the “additional ways” to calculate to either an abstract method or a protected method override-able by subclasses, so that you can have slightly different implementations of MyInterface which provide the different behavior.

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

Sidebar

Related Questions

I would be grateful if someone could help me out here. I'm just starting
I have some code for starting a process (notepad), and dynamically makes a event
Here's a modified version of code from page 586 of Starting Out With C++
Would anybody be able to look through my code real fast and try to
I'm just starting out refactoring my code into multiple assemblies, and feel a bit
Through the following code i look to club all the alphabets with starting with
I was starting to code a library, and decided to do a test, but
I'm using this code as the starting point to an overhaul of our JavaScript
I mainly code small programs for myself, but recently, I've been starting to code
im starting the pseudo code of a new site, and want it to be

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.