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

The Archive Base Latest Questions

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

I’m trying to design a good entity creation system with an abstract factory (as

  • 0

I’m trying to design a good entity creation system with an abstract factory (as per http://www.dofactory.com/Patterns/PatternAbstract.aspx) but I’m struggling when it comes to instance specific parameters.

For example:
I have two abstract factories, one for creating a projectile, and one for creating a crate

Now the factory can be either be one instance for each type, which is passed an abstract parameter set from a list (which in the base class would shared material, size etc), type specific parameters would be velocity for a projectile and durability for a crate.

But what I’m struggling with is, in the end when I have this abstract factory method which I call with parameters like a string “BulletProjectile”, and “WeakCrate”, I need to provide instance specific parameters, and more importantly they are of different types for different factories – for projectiles they would have position and velocity, and crate would just have position.
A worse scenario is when the user or player is creating a crate or similar object, and is able to define its dimensions. How would I handle this?

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

    A couple options:

    Rethink your usage

    An abstract factory is useful if it separates the user of the factory from how the exact type is produced. The abstract factory doesn’t have any restrictions on what it produces, just that it is abstract. It can return a non-abstract type, or an abstract type that isn’t at the very base of your inheritance hierarchy.

    If code that uses the factory already can get different sets of data to call the factory with, then the code using the factory already has some knowledge of the type that comes out of it.

    Here are some options to think about:

    • Provide multiple abstract factory types, with one Create method each, such as a GrenadeFactory and a BulletFactory
    • Provide multiple methods on a single abstract factory type, such as CreateBullet and CreateGrenade
    • Stop using abstract factories. This is a good option if you don’t really need abstract construction, and just need abstract types.

    Remember that you can still pass a derived type (Bullet) to a method taking a base type (say, Entity or Projectile).

    Double dispatch

    If you’re really dead set on combining abstract factories with abstract parameters, then you may want to look into double dispatch, or the Visitor Pattern. The key here is that you’re trying to get two different virtual methods to be combined with each other, and get a unique combination of behavior based on those two derived types.

    This would require you to create base and derived types for your parameters, so you couldn’t pass simple types (like int, string, etc) without creating a custom parameter structure that derived from a base Parameters type.

    It also requires a lot of extra code to implement the Visitor pattern.

    RTTI

    You could use the C++ Run-Time Type Information feature.

    Using dynamic_cast, you can cast a base type to a derived type. You could do this in the factory implementation to cast your base parameter type to your specific parameter type.

    Like double-dispatch, this would also require you to create a type hierarchy for parameters, but would require less code to stitch them together (wouldn’t require the visitor pattern).

    This option would tightly couple your factory implementation to a parameter structure implementation, though.

    Property bag

    You can also use a string -> some type dictionary (string -> boost::any, for example). This is called a property bag. It loses you a lot of compile time type safety, though, because you’re basically looking everything up by string value. I don’t really recommend it.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.