© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
7 replies
Sir Saba

❔ Factory Design method pattern

Hello! Can some one help me with Factory Method, I am working on RPN Calculator project and need to use this design method but I don't understand how it works and how to implement it. ChatGPT gave me a solution but i want to learn how it works.
public interface IOperator
{
    public double Calc(double x, double y);
}



public class Add : IOperator
{ 
    public double Calc(double x, double y) => x+ y;
    
}


//not sure how to do it
public class Div : IOperator
{

    public double Calc(double x, double y)
    {
        try
        {
            return x / y;
        }
        catch (Exception ex)
        {
            // make it in the program.cs that if this function gives 0 => to give "DivideByZeroException" 
            //Or find another solution

            throw new DivideByZeroException("Deiasda");
            return 0;
        }
    }
}
// not sure how to do it because the type is return double and not void 
public class Mod : IOperator
{
    //need to get modified, because of if u get 4 0 % the program should 

    public double Calc (double x, double y)
    {
        return x % y;
    }
}

public class Multi : IOperator
{
    public double Calc (double x, double y)=> x * y;
}

public class Sub : IOperator
{
    public double Calc (double x, double y)=> x - y;
}
public interface IOperator
{
    public double Calc(double x, double y);
}



public class Add : IOperator
{ 
    public double Calc(double x, double y) => x+ y;
    
}


//not sure how to do it
public class Div : IOperator
{

    public double Calc(double x, double y)
    {
        try
        {
            return x / y;
        }
        catch (Exception ex)
        {
            // make it in the program.cs that if this function gives 0 => to give "DivideByZeroException" 
            //Or find another solution

            throw new DivideByZeroException("Deiasda");
            return 0;
        }
    }
}
// not sure how to do it because the type is return double and not void 
public class Mod : IOperator
{
    //need to get modified, because of if u get 4 0 % the program should 

    public double Calc (double x, double y)
    {
        return x % y;
    }
}

public class Multi : IOperator
{
    public double Calc (double x, double y)=> x * y;
}

public class Sub : IOperator
{
    public double Calc (double x, double y)=> x - y;
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Design Patterns / Factory Method
C#CC# / help
17mo ago
✅ Factory Method Pattern
C#CC# / help
17mo ago
✅ Factory method
C#CC# / help
17mo ago
✅ Design pattern for a method feels incorrect
C#CC# / help
4y ago