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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:48:51+00:00 2026-06-05T20:48:51+00:00

Consider a theoretical factory class containing over a thousand of attributes (models, by example,

  • 0

Consider a theoretical factory class containing over a thousand of attributes (models, by example, in a MVC project).

The factory pattern deals to show a scenario snapshot in function a selected level (in a game-like project). The factory has to pass needed components and models to scenarios.

Models and components can be reused by any scenarios, but every scenario can only be initialized only once (it’s impossible to play deals with 2 scenarios).

So, my question is:

Considering that I don’t need every components, I don’t have to initialized the thousand of attributes (because It would be too slow), how can I instantiate the components to pass to scenarios, only if I need it?

I don’t want to make a thousand of factory for each factory (Abstract Factory pattern) and I don’t want to initialised objects in the factory itself, because objects can be reused and I want to avoid copy/paste.

Is there a way to initialized objects on demand, in Java?

I don’t want to receive answer as “It’s a bad conception if you have a thousand of attributes”, I know all of it, but I need to deal with an old system and I would like to reduce the memory usage.

  • 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-05T20:48:52+00:00Added an answer on June 5, 2026 at 8:48 pm

    Nothing built-in, no.

    I’ve done some lazy-initialization tricks using AOP, e.g., as soon as a property is referenced the first time, run initialization. This could be done for long-running initializations only, for all an object’s properties, arbitrary subsets, etc. depending on needs.

    This doesn’t need to be done with AOP, it can be done via normal Java code–but if the Java code has already been written, is coming from a generator outside of your control, etc. it can be problematic.

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

Sidebar

Related Questions

Consider these pseudo models: class City(models.Model): name = models.CharField() region = models.ForeignKey(Region) class Region(models.Model):
Consider following simple DAO example: public abstract class DAOFactory { public abstract AccountDAO getAccountDAO();
Consider this simplified model in Django: class Item(models.Model): title = models.CharField(max_length=200) pub_date = models.DateTimeField()
Consider the following code: template <class x1, class x2 = int*> struct CoreTemplate {
The question is pretty straight forward. For clarity, consider the example below: // Note
Consider: Public MustInherit Class Column Public ReadOnly Property ReturnSomethingUseful() As Object Get 'return something
Consider this a theoretical question as much as practical. One has a table with,
Consider these two classes: public class A { B b; public A(B b) {
Consider this jsfiddle: http://fiddle.jshell.net/maple/JbEJN/show/ (this is the result window, in order for replaceState to
Consider the following class: public class MyIntSet { private List<int> _list = new List<int>();

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.