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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:51:42+00:00 2026-06-16T11:51:42+00:00

I have a declared entity of a class, and want to assign different pre-made

  • 0

I have a declared entity of a class, and want to assign different pre-made templates to it without the templates ever changing. Using a const doesn’t seem to do the trick.

Example:

Weapon w1;
w1 = Sword; // premade weapon.
w1.reducedamage(1); // for example a debuff

In this case the premade weapon’s damage would be decreased, and it would no longer be available as a template. This problem becomes more profound with enemies.

Example:

Enemy enemy;
enemy = enemies[r] // r being a randomly generated integer and enemies a list of enemy templates
Fight(player,enemy); // this method would resolve a fight between the two entities of the type Character.

This problem would not be visible in the player class, since player is a single reference being passed along all the game methods – because there is only one player. Every time the player fights, an enemy template would be “corrupted”.

How would I create templates or classes/structs in general that always pass by value, meaning that the properties of a first class would have the same values as a second, without any relationship between the two classes?

The only success I’ve gotten with this is to create a method that manually copies each attribute of every class that has a template onto another entity of the same class; but this is extremely unpractical since it needs constant upgrading whenever a new class is added, or an old one changed.

  • 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-16T11:51:43+00:00Added an answer on June 16, 2026 at 11:51 am

    I must be missing something. This seems like a reasonably simple issue that is easily solved by inheritance, perhaps in conjunction with some sort of Factory. First, you don’t want to use a reference to a single instance, you want to create a new instance each time so it is a unique object. I prefer classes over structs, but you could easily create a new struct as well. You could use a Factory to create various pre-configured instances of the objects that have pre-defined values. For example, the Sword of Damocles or the Sword of Destiny.

    public static class WeaponFactory
    {
           public static Weapon CreateSword(SwordType type)
           {
                var sword = new Sword(); // plain, old default sword
    
                // override properties based on type
                switch (type)
                {
                    case SwordType.SwordOfDamocles:
                        sword.FallTime = GetRandomFutureTime();
                        break;
                    case SwordType.SwordOfDestiny:
                        sword.Invincible = true;
                        break;
                    ...
                }
    
                return sword;
            }
    
            ...
    }
    

    Alternative using Actions

    public static class WeaponFactory
    {
          public static Weapon Create<T>(Action<T> decorator) where T : IWeapon, new()
          {
               var weapon = new T();
               decorator(weapon);
               return weapon;
          }
    
          public static void SwordOfDamocles(Sword sword)
          {
               sword.FallTime = GetRandomFallTime();
          }
    
          public static void SwordOfDestiny(Sword sword)
          {
               sword.Invincible = true;
          }
    }
    
    var weapon = WeaponFactory.Create(WeaponFactory.SwordOfDamocles);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a variable declared like this in a class: Entity *array[BOARD_SIZE][BOARD_SIZE]; I need
I have a class declared as @Entity @Table(name = word, schema = public) public
I have a tags property declared like that : @Entity public class BlogArticle {
I am using entity framework code first, I have 2 entities declared like so:
So long story short I have an object model in which several different entity
I have a subclass of a class named Entity, and I wan't that subclass
Why can't an entity class in JPA be final or have a final methods?
I have a base Entity class which will be derived in more than a
I have an entity which is declared roughly like: @Entity @Table(name = myUserTable) public
In my program I have a class named Entity. Another class Invader inherits Entity.

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.