locked
Factory Design Pattern error RRS feed

  • Question

  • User1002530435 posted

    Hi,

         I have done a sample factory pattern.But it throwing this below error .please help me and let me know where i done mistake

    Error 1 'FactoryPattern.Program' does not implement interface member 'FactoryPattern.IFactory.Select()

    My factory code

        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;
    
        namespace FactoryPattern
        {
            interface IFactory
            {
                    VehicleFactory Select();
            }       
            class CarFactory:IFactory
    	{
                public VehicleFactory Select()  
                {
                return new Car();
                }
            }
            class ScooterFactory : IFactory
            {
               public VehicleFactory Select()
                {
                 return new Scooter();
                }
    	}
            abstract class VehicleFactory
    	{
    	   public abstract void Start();
    	}
            class Car:VehicleFactory
    	{
    	   public override void  Start()
                {
                Console.WriteLine("You selected car");
                }
    	}
            class Scooter:VehicleFactory
    	{
              public override void Start()
                {
                Console.WriteLine("You selected Scooter");
                }
    	}
          }
    

       
    
    
    

    My Program.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace FactoryPattern
    {
        class Program:IFactory
        {
            static void Main(string[] args)
            {
                IFactory factory = LoadFactory("car");
                VehicleFactory vehiclefactory =  factory.Select();
                vehiclefactory.Start();
                Console.ReadLine();
            }
    
            private static IFactory LoadFactory(string snack)
            {
                switch (snack)
                {
                    case "car":
                        return new CarFactory();
                    default:
                        return new ScooterFactory();
                        break;
                }
            }
        }
    }
        

    Pleasehelp!

    Friday, January 9, 2015 6:27 AM

Answers

  • User1002530435 posted

    Got it :) but feeling guilty :( ... as its a very basic error Cry   ..Any now am happy :)Cool ..thanks who are all viewed :)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 9, 2015 6:36 AM