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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:10:50+00:00 2026-05-26T10:10:50+00:00

There is a logic and properties used to create certain object. That logic is

  • 0

There is a logic and properties used to create certain object. That logic is going to repeated in several classes. Like some template logic. e.g. suppose I am creating a template to create enums like objects, which basically requires setting an int in constructor and getting value through method.

There are two ways to do this

  1. Create a template superclass which has both of these logics, and extending it whenever we need to create an enum like object.

  2. Create and re write both the logics every where.

Keeping memory and performance of code in mind which option is preferable. What are the pros and cons for it?

  • 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-26T10:10:50+00:00Added an answer on May 26, 2026 at 10:10 am

    As always memory consumption and performance are secondary to readability and maintainability.

    If I were you, I would sit down and think about where the logic belongs logically, and put it there. You could for instance ask yourself, Which solution would be easiest for me to defend for someone reading my code for the first time?

    If the logic sort of spans across all subclasses (i.e. if you can’t extend the class without dealing with this logic) put it in the super class.

    If the logic is truly specific to all subclasses, then put it in the subclasses.

    If you go for the later, consider writing it in a way such that you can enforce the logic to be implemented through abstract methods in the super class.


    (BTW, your question, and the enum-tag isn’t really clear. You can’t instantiate enums in runtime in Java.)

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

Sidebar

Related Questions

I'm trying to implement some retry logic if there is an exception in my
Is there any reason something like this would not work? This is the logic
We always write functions or classes and their logic is very complicated. If there
I have a class with a lot of Decimal properties that are used for
OK so I'm looking a some code which looks roughly like this: void DoSomething(object
There's loads of choices for .ico files but I can't see any logic in
I have a click handler, which has event.preventDefault. There is whole lot of logic
During the course of our application login there are several queries ran, all around
I just realized that the C# property construct can also be used with a
I use some strongly-typed expressions that get serialized to allow my UI code to

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.