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

  • Home
  • SEARCH
  • 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 8297009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:14:38+00:00 2026-06-08T15:14:38+00:00

I want to use the strategy pattern in Java. However, my boss doesn’t like

  • 0

I want to use the strategy pattern in Java. However, my boss doesn’t like it if I add lots of files to the code base or write verbose code. It seems that with the strategy pattern I’d have to make one file for an interface and then five additional files so I can have a class for each of my five possible strategies.

Is there a way to express the strategy pattern in Java with fewer files and less code?

I think it would be ideal if my strategy variations could be represented on an Enum or one Set that is easy to assemble.

  • 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-06-08T15:14:40+00:00Added an answer on June 8, 2026 at 3:14 pm

    I think you should sit down with your boss and explain to him/her that less files != good code. At least attempt to explain the pattern itself and how having multiple classes, each with it’s own specific purpose is better for testing, maintenance, etc….

    Personally, i find code more verbose with lots of IF statements littered about the place where proper polymorphism would make the code much easier to understand.

    PS: And yes, enums can have behavior by using the anonymous subclassing construct:

    public enum Foo {
       BAR() {
         public void baz() { ... }
       };
    
       public abstract void baz();
    }
    

    Though i’m not sure i’d recommend using that unless you absolutely have to.

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

Sidebar

Related Questions

I want to add exception handling in Mule ESB using custom-exception-strategy. However, I have
I want use this 1 for using Bar code or QR code scanner. I
I don't want use old Visual Basic methods in my code, and I'm confused
I want to use observer pattern for a logging system. We have got logObservers
When connecting using the Facebook strategy, I want to use display=popup in the Facebook
I often get into situation when I'd like to use template method pattern, but
Goal: I want to use the Observer Pattern so that when one uiimageview receives
I want to use SEQUENCE strategy for automatically generate ids, but i am breaking
I want use BYTE_ORDER macro in my Xcode project but i can't because i
I want use javascript setInterval function to achieve a box rotate animate effect, I

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.