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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:20:30+00:00 2026-05-15T08:20:30+00:00

First thing… I am novice to pattern world, so correct me if wrong anywhere

  • 0

First thing… I am novice to pattern world, so correct me if wrong anywhere
Scenario:
There are multiple companies providing multiple products of diff size

so there are 3 entities i.e. Companies, Their Product and size of product

I have implement Abstract Pattern on this i.e. so that I will create instance of
IProductFactory interface to get desired product…

Is below implementation of Abstract Factory Pattern correct ??? If not then please correct the approach
+
Also tell me if any other pattern can be used for such scenario
Thanks in advance…

public enum Companies
{
    Samsung = 0,
    LG = 1,
    Philips = 2,
    Sony = 3
}

public enum Product
{
    PlasmaTv = 0,
    DVD = 1
}

public enum ProductSize
{
    FortyTwoInch,
    FiftyFiveInch
}

interface IProductFactory
{
    IPhilips GetPhilipsProduct();
    ISony GetSonyProduct();
}

interface ISony
{
    string CreateProducts(Product product, ProductSize size);
}
interface IPhilips
{
    string CreateProducts(Product product, ProductSize size);
}

class ProductFactory : IProductFactory
{
    public IPhilips GetPhilipsProduct()
    {
        return new Philips(); 
    }

    public ISony GetSonyProduct()
    {
        return new Sony();
    }
}

class Philips : IPhilips
{
    #region IPhilips Members

    public string CreateProducts(Product product, ProductSize size)
    {// I have ingnore size for now....
        string output = string.Empty;
        if (product == Product.PlasmaTv)
        {
            output = "Plasma TV Created !!!";
        }
        else if (product == Product.DVD)
        {

            output = "DVD Created !!!";
        }
        return output;
    }

    #endregion
}

class Sony : ISony
{// I have ingnore size for now....
    #region ISony Members
    public string CreateProducts(Product product, ProductSize size)
    {
        string output = string.Empty;
        if (product == Product.PlasmaTv)
        {
            output = "Plasma TV Created !!!";
        }
        else if (product == Product.DVD)
        {

            output = "DVD Created !!!";
        }
        return output;
    }
    #endregion
}



IProductFactory prodFactory = new ProductFactory();
IPhilips philipsObj = prodFactory.GetPhilipsProduct();
MessageBox.Show(philipsObj.CreateProducts(Product.DVD, ProductSize.FortyTwoInch));

or

//ISony sonyObj = prodFactory.GetSonyProduct();
//MessageBox.Show(sonyObj.CreateProducts(Product.DVD, ProductSize.FortyTwoInch));
  • 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-15T08:20:31+00:00Added an answer on May 15, 2026 at 8:20 am

    No, it should rather look like this:

    interface IProductFactory
    {
        string CreateProducts(Product product, ProductSize size);
    }
    
    class SonyProductFactory : IProductFactory
    {
        string CreateProducts(Product product, ProductSize size) { ... }
    }
    class PhilipsProductFactory : IProductFactory
    {
        string CreateProducts(Product product, ProductSize size) { ... }
    }
    
    ...
    IProductFactory prodFactory = loadProductFactory();
    MessageBox.Show(prodFactory.CreateProducts(Product.DVD, ProductSize.FortyTwoInch));
    

    loadProductFactory() returns a Sony or Philips factory, maybe based on configuration, or application state. This functionality could be moved into a separate factory loader class as well, to make it more reusable.

    Update: A trivial implementation could be

    IProductFactory loadProductFactory() {
        String factoryName = System.getProperty("factory.name");
        if (factoryName.equals("Sony") {
            return new SonyProductFactory();
        } else {
            return new PhilipsProductFactory();
        }
    }
    

    A more robust version could load the concrete product factory classname from a config file, load the class, verify that it is an IProductFactory, then return an instance of it. This has the benefit that there are no more dependencies to any concrete product factory class, so adding/changing/removing factory implementations requires no recompilation of the sources, only a config file change.

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

Sidebar

Related Questions

First thing: I know that there is interface to W3C validator: http://pear.php.net/package/Services_W3C_HTMLValidator/ But I
OK, first thing I want to say is: yes, I know there are a
First thing first, I know there are many questions regarding python and lxml on
First thing is I am on Ubuntu 12.04 LTS. When I type rails s
First thing i want to say that it's not an easy question to explain,
The first thing that comes to my mind is to do a bunch of
I was just reading this line: The first thing the format() method does is
I'm just taking my first steps with Azure and the first thing I see
I have some jQuery/JS below. The first thing to run is the alert box
To begin with, I don't know the first thing about Python ... so I

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.