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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:09:00+00:00 2026-05-23T08:09:00+00:00

Classical implementation of Abstract Factory/Factory method is based on polymorphism. But on the lowest

  • 0

Classical implementation of Abstract Factory/Factory method is based on polymorphism. But on the lowest level we have to have some kind of factory which is not based on polymorphism and breaks open-closed principle:

public Device Create(string deviceName)
{
  switch (deviceName)
  {
    case "Device1": return new Device1();
    case "Device2": return new Device2()'
    default: throw new NotSupportedDeviceException(deviceName);
  }
}

Is there any special name for this kind of factories?

  • 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-23T08:09:01+00:00Added an answer on May 23, 2026 at 8:09 am

    From what I can see, you’ve posted a perfectly valid example of the Factory Method pattern:

    • Both Device1 and Device2 inherit/implement the Device class/interface – polymorphism is still a key aspect of this example.
    • You’re using the Factory Method to encapsulate the logic to determine which concrete class to instantiate and return.
    • The caller of the factory method remains nicely ignorant of the concrete classes involved – he just knows he gets back a Device. Which is exactly what you want a Factory Method to do for you.

    It’s true, the internal implementation is a little heavy-handed (switch-case). However, that doesn’t make it any less of a true Factory Method pattern.

    I don’t really see where your example “isn’t based on polymorphism” nor where it “breaks the open/closed principle”. If I’ve missed the point entirely, feel free to update your post, to help us zero in on your question.

    Now if the Factory method was taking the passed deviceName, and using it to find an exact match of the concrete class to instantiate (using reflection), that would absolutely break the Factory Method pattern, because the caller would have to have intimate knowledge of the different concrete classes. But as currently written, the passed deviceName is just a piece of data used in the decision-making process – it doesn’t break the encapsulation of the factory pattern.

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

Sidebar

Related Questions

I have a web system which has a classical parent-children menu saved in a
I have the classical Symphony flash message implementation: $_SESSION['flash'] = This is a flash
I have the classical table with expandable and collapsible records that if expanded show
I have an ecommerce website that works in a classical way: people sign up,
I wonder how many of you have implemented one of computer science's classical algorithms
I have a set of elements which I want to perform operations on. The
I'm not looking for an implementation, just pseudo-code, or at least an algorithm to
I have a problem which I believe is the classic master/worker pattern, and I'm
I'd like to implement a method which allows me to access a property of
I'm looking for some strategic advise on the implementation of an application that supports

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.