コード例 #1
0
        /// <summary>
        /// Entry point
        /// Creates car getter that takes file names from command line
        /// Creates menu with list of car catalogs
        /// </summary>
        /// <param name="args">The command line arguments</param>
        static void Main(string[] args)
        {
            try
            {
                // Checks for 2 file names
                if (args.Length != 2)
                {
                    throw new Exception("File names are not specified");
                }

                CarGetter carGetter = CarGetter.GetInstance();

                List <CarCatalog> catalogs = new List <CarCatalog>()
                {
                    new CarCatalog(carGetter.GetCars(args[(int)CarType.Passenger])),
                    new CarCatalog(carGetter.GetCars(args[(int)CarType.Truck]))
                };

                Menu menu = new Menu(catalogs);
                menu.Display();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }
        }
コード例 #2
0
        /// <summary>
        /// Singleton pattern
        /// Creates an object if it does not exist
        /// </summary>
        /// <returns>CarGetter object</returns>
        public static CarGetter GetInstance()
        {
            if (_instance == null)
            {
                lock (_syncRoot)
                {
                    if (_instance == null)
                    {
                        _instance = new CarGetter();
                    }
                }
            }

            return(_instance);
        }