Last active
April 3, 2026 08:27
-
-
Save Vitka999/b26fa178d757795fa35c9d139137867c to your computer and use it in GitHub Desktop.
Adapter Bridge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <string> | |
| #include <memory> | |
| using namespace std; | |
| class IDevice { | |
| public: | |
| virtual ~IDevice() = default; | |
| virtual string GetName() const = 0; | |
| virtual string GetSpecifications() const = 0; | |
| }; | |
| class VideoCard : public IDevice { | |
| public: | |
| string GetName() const override { | |
| return "Video Card NVIDIA GeForce RTX 4070"; | |
| } | |
| string GetSpecifications() const override { | |
| return "Memory: 16 GB GDDR6X, Core Clock: 1920"; | |
| } | |
| }; | |
| class Processor : public IDevice { | |
| public: | |
| string GetName() const override { | |
| return "Processor Intel Core i7-13700K"; | |
| } | |
| string GetSpecifications() const override { | |
| return "Cores: 16, Threads: 24, Frequency: 3.4–5.4"; | |
| } | |
| }; | |
| class HardDrive : public IDevice { | |
| public: | |
| string GetName() const override { | |
| return "Hard Drive Seagate Barracuda 2TB"; | |
| } | |
| string GetSpecifications() const override { | |
| return "Type: HDD, Speed: 7200 RPM, Interface: SATA III"; | |
| } | |
| }; | |
| class RAM : public IDevice { | |
| public: | |
| string GetName() const override { | |
| return "RAM Kingston Fury 32GB DDR5"; | |
| } | |
| string GetSpecifications() const override { | |
| return "Type: DDR5, Frequency: 5600 MHz, Timings: CL36"; | |
| } | |
| }; | |
| class DeviceReport { | |
| protected: | |
| shared_ptr<IDevice> device; | |
| public: | |
| explicit DeviceReport(shared_ptr<IDevice> dev) : device(move(dev)) {} | |
| virtual ~DeviceReport() = default; | |
| virtual void PrintReport() const = 0; | |
| }; | |
| class SimpleReport : public DeviceReport { | |
| public: | |
| explicit SimpleReport(shared_ptr<IDevice> dev) : DeviceReport(move(dev)) {} | |
| void PrintReport() const override { | |
| cout << "Device: " << device->GetName() << endl; | |
| cout << "Specifications: " << device->GetSpecifications() << endl; | |
| cout << endl; | |
| } | |
| }; | |
| class DetailedReport : public DeviceReport { | |
| public: | |
| explicit DetailedReport(shared_ptr<IDevice> dev) : DeviceReport(move(dev)) {} | |
| void PrintReport() const override { | |
| cout << "==============================================" << endl; | |
| cout << " DEVICE SPECIFICATIONS REPORT " << endl; | |
| cout << "----------------------------------------------" << endl; | |
| cout << "Name: " << device->GetName() << endl; | |
| cout << "Detailed Specifications: " << device->GetSpecifications() << endl; | |
| cout << "==============================================" << endl << endl; | |
| } | |
| }; | |
| int main() { | |
| shared_ptr<IDevice> gpu = make_shared<VideoCard>(); | |
| shared_ptr<IDevice> cpu = make_shared<Processor>(); | |
| shared_ptr<IDevice> hdd = make_shared<HardDrive>(); | |
| shared_ptr<IDevice> ram = make_shared<RAM>(); | |
| SimpleReport report1(gpu); | |
| DetailedReport report2(cpu); | |
| SimpleReport report3(hdd); | |
| DetailedReport report4(ram); | |
| report1.PrintReport(); | |
| report2.PrintReport(); | |
| report3.PrintReport(); | |
| report4.PrintReport(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment