Calculate Interface RRS feed

  • Question

  • Hello Friends, I was wondering how i could use the Gof Factory Method Design Pattern using a Calculate Interface. I am just asking this for learning purposes.  I thought that this would be a simple way to start out. I'm thinking that i would design a calculator user interface and then create my object methods for calculation based on whether the user clicks on an add, subtract, divide, or multiply button. Thanks !

    • Edited by Ronald Rex Tuesday, January 8, 2019 7:55 AM
    Tuesday, January 8, 2019 7:48 AM

All replies

  • E.g.

    public interface ICalculator { }
    public class Program
        public ICalculator CreateCalculator() {
            ICalculator result = null;
            // Implement creation.
             return result;

    Tuesday, January 8, 2019 9:10 AM
  • This is not the Gof Factory Method Design Pattern??????????
    Wednesday, January 9, 2019 9:42 PM
  • Sure...

    You don't have given details for Product and ConcreteProduct, thus I'm using only the interface. And while Creator should be abstract and the FactoryMethod in ConcreteCreator is optional, I just shortened it.

    Maybe you can rephrase your question. Add more context and code.

    Especially as your mentioned methods (add, multiply, etc.) sounds like the Command pattern.

    Friday, January 11, 2019 11:37 AM