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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:37:59+00:00 2026-05-29T22:37:59+00:00

I have a StaffFactory for getting Staff objects by various means, but I also

  • 0

I have a StaffFactory for getting Staff objects by various means, but I also have some setup methods to determine which data source to use.

class StaffFactory
{
    private const string DefaultDbSourceName = "Production";
    private string dbSourceName;
    #region Factory Management
    private static Dictionary<string, StaffFactory> staffFactories = new Dictionary<string,StaffFactory>();
    public static StaffFactory GetInstance()
    {
        return GetInstance(DefaultDbSourceName);
    }
    public static StaffFactory GetInstance(string dbSourceName)
    {
        if (!staffFactories.ContainsKey(dbSourceName))
        {
            staffFactories.Add(dbSourceName, new StaffFactory(dbSourceName));
        }
        return staffFactories[dbSourceName];
    }
    private StaffFactory(string dbSourceName)
    {
        this.dbSourceName = dbSourceName;
    }
    #endregion Factory Management
    #region Factory Methods
    public Staff ById(int id) { ... }
    public IList<Staff> ByName(string name) { ... }
    ...
    #endregion Factory Methods
}

As I go to create my next factory, I realise all this management logic is going to remain the same regardless of what type the factory is for. So I’m thinking I create some base Factory or Factory class that houses that logic, and then my declare the above with class StaffFactory : Factory<Staff> { ... } or something, but I’m drawing complete blanks on how I would go about that. Whether or not to implement it using generics, etc.

Can anyone point me in the right direction?

  • 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-29T22:38:01+00:00Added an answer on May 29, 2026 at 10:38 pm

    Before you introduce a new abstraction layer, make sure that the benefits will outweigh the costs. In your case, those would include:

    The cost to design and implement the abstraction

    StaffFactory is much easier to design, implement and test than a generic Factory<T> class.

    The cost to understand the Factory<T> abstraction

    Every time someone reads the code, they may need to wrap their head around the abstraction. A generic abstraction is harder to wrap your head around than a non-generic one.

    The cost to make changes in the future

    Let’s say that you have Factory<Staff> and Factory<Product>, and in the future you find that you want a different caching policy for the two. Maybe the Factory<Product> should discard the cached object if the cache size exceeds some threshold.

    Are you going to generalize the Factory<> class to support different modes? That can be done, but its much more complex than just modifying StaffFactory and ProductFactory classes independently.

    Summary

    So, don’t introduce an abstraction just for the sake of it. And, definitely do not generalize StaffFactory into a generic Factory<T> if Factory<Staff> is going to be the only generic instantiation you’ll have.

    From your code above, it seems that your Factory<T> class would be basically a Dictionary<string, T>. If that’s the case, then introducing the additional generic Factory class does not get you much benefit and only adds an unnecessary abstraction layer.

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

Sidebar

Related Questions

Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have converted devise new session from erb to Haml but doens't work, this is
Have searched the database but need to specifically sum(of hours flown or days off)in
Have a rather abstract question for you all. I'm looking at getting involved in
Have created a ATL COM project through which I am inserting Menu Items to
Have some dates in my local Oracle 11g database that are in this format:
Have anyone used Redmine Documentor which lets you convert PHP to HTML to Redmine
Have the following scenario. I have a few form, which essentially have a few
Have an app that can use tts to read text messages. It can also
Have a bunch of classes which I need to do serialize and deserialize from/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.