static public IInvoice GetInvoice(int invoiceType)
        {
            IInvoice objInvoice;

            if (invoiceType == 1)
            {
                objInvoice = new InvoiceWithHeader();
            }
            else if (invoiceType == 2)
            {
                objInvoice = new InvoiceWithoutHeader();
            }
            else
            {
                return(null);
            }
            return(objInvoice);
        }
Ejemplo n.º 2
0
        public static IInvoice GetInvoice(int invoiceType)
        {
            IInvoice objInvoice;

            switch (invoiceType)
            {
            case 1: objInvoice = new InvoiceWithHeader(); break;

            case 2: objInvoice = new InvoiceWithoutHeader(); break;

            case 3: objInvoice = new InvoiceWithFooter(); break;

            case 4: objInvoice = new InvoiceWithoutFooter(); break;

            default:
                objInvoice = null;
                break;
            }

            return(objInvoice);
        }
Ejemplo n.º 3
0
    internal void Main()
    {
        //CREATION - FACTORY PATTERN

        /*
         * Learning Reference
         * https://refactoring.guru/design-patterns/factory-method
         * https://www.javatpoint.com/factory-method-design-pattern
         */
        Console.WriteLine("CREATION - FACTORY PATTERN");
        Console.WriteLine(">> With user input");

        /*
         * Client only knows about InvoiceCreator's GetInvoice/PerformAction,
         * based on Type of Creator send as parameter
         */
        InvoiceCreater invoice = new InvoiceCreater();

        invoice.GetInvoice(invoiceType: EnumInvoiceType.WithHeader);
        invoice.GetInvoice(invoiceType: EnumInvoiceType.WithOutHeader);

        Console.WriteLine(Environment.NewLine + ">> WithOut user input");

        /*
         * Client only knows about InvoiceCreator's PerformAction,
         * based on Type of Creator created
         */
        AInvoiceCreater invoiceCreater;

        invoiceCreater = new InvoiceWithHeader();
        invoiceCreater.PerformAction();
        invoiceCreater = new InvoiceWithoutHeader();
        invoiceCreater.PerformAction();

        /*
         * New type of Invoice can be added later by just
         * Creating Creator and Concreate Class
         * InvoiceWithoutHeaderCreater * InvoiceWithoutHeader
         */
    }