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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:52:53+00:00 2026-05-12T09:52:53+00:00

I’m working in AS3, but I guess this could be a general question, so

  • 0

I’m working in AS3, but I guess this could be a general question, so I’ll frame it more vaguely…

I’m using an XML file to define parameters for a particular class of object that implements the Strategy Pattern. There will be large variety of objects, and this works for us as a designer friendly solution to customizing these objects. As I can only define strings in the XML file, can someone suggest a tidy way to get take that string and implement the proper strategy?

I had two initial thoughts. Firstly, to pass the string to the constructor of the object and then have a Switch Case within the object that applies the correct strategy.

Secondly, so put the switch outside of the class in the controller that then passes the correct strategy to the object’s constructor.

The second seems like the cleaner version as then the object class itself isn’t affected by my specific implementation. But neither feels quite right.

Any additional suggestions would be appreciated!

  • 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-12T09:52:53+00:00Added an answer on May 12, 2026 at 9:52 am

    You want some kind of Factory design pattern, to pick the appropriate class based on an input string. A nice application of that is Registry, where applicable classes “register” themselves with a singleton Registry class as being appropriate for a certain input string; the factory itself then just becomes a lookup from string to registered class. Some fallback needs to be present when no class has registered for the input string that’s being requested: either that’s an exception, or there’s a “default” implementation that gets used when no more specific one applies — the latter’s a nice fail-soft option, but not always applicable.

    An inevitable issue with Registry is, how to locate all classes of interest and make sure they register themselves (that’s particularly of interesting for Plugin classes); the best solutions to this are rather dependent on the specific language at hand and unfortunately I’m not sure what AS3 delivers in this regard (or if you’re at all interested in such dynamic expandability).

    Another interesting issue with Registry is “conflicts” — what happens if more than one applicable class claims to be the right one for a certain input string. “Last to claim wins” is simplest, but often too-simple; you may have each class register for multiple input strings with a certain “precedence” or “priority”, or else (not really interesting on systems that aren’t distributed, but crucial for distributed systems…) “load balance” among all applicable “servers” (round-robin or in more sophisticated ways).

    You’ll note that these solutions resemble your second one more than your first one, but the key difference is that instead of a brittle, rigid hard-coded switch (an OOP bete noire;-) they rely on flexible mappings from string to class (or class-constructing method, delegate, &c, depending on details of implementation language — e.g. in Java you might have a StrategyConstructing interface, each strategy class would then register its own auxiliary class implementing that strategy when it signs up to the Registry).

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

Sidebar

Related Questions

No related questions found

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.