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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:36:36+00:00 2026-06-15T03:36:36+00:00

I’m having trouble implementing the Factory Design Pattern. I’ve looked at http://dotnet.dzone.com/articles/design-patterns-c-factory , which

  • 0

I’m having trouble implementing the Factory Design Pattern. I’ve looked at
http://dotnet.dzone.com/articles/design-patterns-c-factory,
which follows my design very closely since it was the first good example I found a while back.
I took a look at
Abstract Factory Design Pattern,
but my design is very different and I’m having trouble deciding if I need that.

Right now, this is what it looks like. It used to be more simple, with my CR5, interface, factory, CB_spec, El, etc in the same visual studio project. I had to move things around as shown per design discussions and the need for CR6, etc to be separate. Now I’m getting some compilation problems I’m not sure what to do with. See ** below. My question is regarding the two compilation issues below.

My iCR Visual Studio project:

    public interface iCR
    {
        int CB_IO_Init(int slaveIndex);
        int WritePortReady();
        int WritePortBusy();
        void initCRData(byte[] writeBuffer, byte[] statusBuffer, int SlaveIndex, USB_Comm.CB cb, int cr_Type);
        int ProcessTWriting(ref Byte[] writeDat, ref Byte[] statusDat, ref Byte[] dataDumpWriteCheck);
        void Failure(String message);
        void Success(String message);

    }

My CR_Factory Visual Studio project

namespace CR_Factory
{

public class Cr
{

}  

public class CRFactory
{
    public enum CRType
    {
        CR0,
        CR1,
        CR3,
        CR4,
        CR5,
        CR6
    }

    public CRFactory()
    {
    }

    public iCR GetCR(CRType type) 
    {
        iCR cr = null;
        switch (type)
        {
            case CRType.CR5:
                cr = new CR5(); //**compile error..Cannot implicitly convert type ‘CR5’ to iCR’. An explicit conversion exists (are you missing a cast?)
                break;
            case CRType.CR6:
                //not done yet
                break;
            default:
                throw new ArgumentException(string.Format("A CR of type {0} cannot be found", Enum.GetName(typeof(CRType), type)));
        }
        return cr;
    }

    public CRType DetermineCR_Type(int type)
    {
        switch (type)
        {
            case 0:
                return CRType.CR0;
            //break;
            case 1:
                return CRType.CR1;
            case 3:
                return CRType.CR3;
            case 4:
                return CRType.CR4;
            case 5:
                return CRType.CR5;
            case 6:
                return CRType.CR6;
            default:
                throw new ArgumentException(string.Format("A type of type {0} cannot be found", type));

        }
    }

    }
}

My CR5 Visual Studio Project has a lot of classes in it, but right now I’m just showing you the part referred to in the factory. Later I’ll create a CR6 VS project, etc.:

public class CR5 : iCR
{        


    CB_703 cb_specific = null;

    //constructor
    public CR5()
    {
        cb_specific = new CB_703(SlaveIndex);
    }


    public int CB_IO_Init(int SlaveIndex)
    {
        int result = -534;
        result = cb_specific.IO_Init(SlaveIndex);
        return result;
    }
.
.
.
}

I have another Visual Studio Project (actually several) that instantiates the factory and gets the appropriate type. We’ll call it El:

namespace CrWr
{

public partial class PControl : UserControl
{
    //setup 

    //constructor
    public PControl()
    {

    }

    /// <summary>
    /// Get the P Control for chosen dll
    /// </summary>
    public Control GetPControl(USB_Comm.CB cbInstance, string dllSelected, THandlerApplication.Temp.TEMP[] temp, string dll, SC.SC.S_C c0)
    {
        cb = cbInstance;
        createControls();
        itsDll = dll;
        tArr = temp;
        cert = c0;

        CR_Factory.CRFactory factory = new CR_Factory.CRFactory();
        CRFactory.CRType type = factory.DetermineCR_Type(cr_Type);
        try
        {
            cr = factory.GetCR(type); //**compile error GetCR is not supported by the language
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.InnerException);
        }
        return this;
    }

private void OnP()
    {
        int result = -536;

        while (rL)
        {
            result = cr.CB_IO_Init(SlaveIndex); 
            if (result == 0)
            {
                …
            }
        }

.
.
.
}
  • 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-06-15T03:36:37+00:00Added an answer on June 15, 2026 at 3:36 am

    The problem wound up being that I had a reference to the same class in both my interface parameter and also the CR5 project. Since it was circular, it was causing weird compilation errors. This happened when I moved things around to get ready for the factory to use the CR6 class.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.