خرید بک لینک

Vote count: 1

I realise this has a very broad title.

My knowledge of OO is lacking as I have not done it in a few years although I think my concepts are correct.

I am creating a custom PerformanceMonitor that reads real-time information from your computers hardware. I'm coding this is C#. Example classes:

Machine

namespace PerformanceMonitor
{
    public static class Machine
    {
        public static CPU cpu { get; set; } = new CPU();
        public static RAM ram { get; set; } = new RAM();
        public static List<GPU> gpus { get; set; } = new List<GPU>();
        public static List<Drive> drives { get; set; } = new List<Drive>();

        static Machine() {}
    }
}

CPU

namespace PerformanceMonitor
{
    public class CPU
    {
        public List<CPUCore> cpuCores { get; set; } = new List<CPUCore>();
        public bool HyperThreaded { get; set; } = false;

        public int ClockBusSpeed_current { get; set; }
        public int ClockBusSpeed_max { get; set; }

        public int TemperaturePackage_current { get; set; }
        public int TemperaturePackage_max { get; set; }

        public int LoadTotal_current { get; set; }
        public int LoadTotal_max { get; set; }

        public int PowerPackage_current { get; set; }
        public int PowerPackage_max { get; set; }

        public int PowerGraphics_current { get; set; }
        public int PowerGraphics_max { get; set; }

        public int PowerDRAM_current { get; set; }
        public int PowerDRAM_max { get; set; }

        public int PowerCores_current { get; set; }
        public int PowerCores_max { get; set; }

        public CPU() {}
    }
}

CPUCore

namespace PerformanceMonitor
{
    public class CPUCore : CPU
    {
        public CPUCore() {}
    }
}

Machine is a top-level class, if you will. Every time an instance of Machine is created, an instance of all other classes listed are created as well. For example, if you wanted to set that the CPU is hyperthreaded, you would do something to this effect in Program.cs:

private static Machine machine = new Machine();
...
if (NumberOfCores * 2 == NumberOfLogicalProcessors) {
    machine.cpu.HyperThreaded = true;
}

So you will access everything through the Machine class.

Every time the program is run, only 1 instance of each class will be created (except CPUCore, GPU and Drive - this is why I'm attempting to use static)

The Machine class (and therefore, any class) will only be accessed through the Program class. This class will also be the only one interacting with the WMI to get the required information.

My questions are:

  • Even though nothing is in the constructor of each class, will the instance see that the class has those specific attributes or do they have to be newly created in the constructor? i.e:

    public static CPU cpu { get; set; } ... static Machine() { cpu = new Cpu(); }

  • Am I using the 'static' keyword correctly here?

  • Should/can I also implement the list of classes as static even though the class itself is not? I.e:

    public static List<GPU> gpus

  • Should I also implement the keyword sealed in any of these classes so they caot be overridden?

I realise this is along question so if you think it's better to point me at a book/web site on OOP/ design pattes then do so.

Also, if you see a fault in my OO design that I fail to see then please point it out. Thank you!

asked 5 mins ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 19 خرداد 1395 ساعت: 1:51

صفحه بندی