Пример #1
0
        static void Main(string[] args)
        {
            Computer comp = new Computer();

            comp.Start("macOS Big Sur");
            Console.WriteLine(comp.OS.Name);

            //we can't change OS, because the object has been already created
            comp.OS = OS.GetInstance("Windows 10");
            Console.WriteLine(comp.OS.Name);

            //Before: macOS Big Sur, Windows 10

            (new Thread(() =>
            {
                Computer comp2 = new Computer();
                comp2.OS = OsLock.GetInstance("Windows 10");
                Console.WriteLine(comp2.OS.Name);
            })).Start();

            Computer comp = new Computer();

            comp.Start("macOS Big Sur");
            Console.WriteLine(comp.OS.Name);

            //After: macOS Big Sur, macOS Big Sur
        }
Пример #2
0
 }                                //there could be just one operating system on a computer
 public void Start(string osName) //launch the operating system
 {
     OS = OsLock.GetInstance(osName);
 }