From 7723e6818644d12827f39bda87109965740b63a4 Mon Sep 17 00:00:00 2001 From: Shaquille Soekhlal Date: Sun, 11 Jun 2023 16:15:15 +0200 Subject: [PATCH] Opdracht 4 code en design Co-authored-by: Aryan Lala (19097727) --- Opdracht_4/Application/main.cpp | 0 Opdracht_4/Domein/Machine.cpp | 1 - Opdracht_4/Domein/Machine.h | 4 - Opdracht_4/Domein/Mone.cpp | 1 - Opdracht_4/Domein/Mone.h | 4 - Opdracht_4/Domein/Motor.cpp | 1 - Opdracht_4/Domein/Motor.h | 4 - Opdracht_4/Domein/Mtwo.cpp | 1 - Opdracht_4/Domein/Mtwo.h | 4 - Opdracht_4/Domein/Sensor.cpp | 1 - Opdracht_4/Domein/Sensor.h | 4 - .../DomeinImplementatie/MachineImpl.cpp | 1 - Opdracht_4/DomeinImplementatie/MachineImpl.h | 4 - Opdracht_4/DomeinImplementatie/MoneImpl.cpp | 1 - Opdracht_4/DomeinImplementatie/MoneImpl.h | 13 + Opdracht_4/DomeinImplementatie/MtwoImpl.cpp | 1 - Opdracht_4/DomeinImplementatie/MtwoImpl.h | 4 - Opdracht_4/DomeinImplementatie/SensorImpl.cpp | 1 - Opdracht_4/DomeinImplementatie/SensorImpl.h | 4 - Opdracht_4/UserInterface/UI.cpp | 1 - Opdracht_4/UserInterface/UI.h | 4 - Opdracht_4/inc/DieselMotor.cpp | 20 ++ Opdracht_4/inc/DieselMotor.h | 17 ++ Opdracht_4/inc/ElectrischeMotor.cpp | 20 ++ Opdracht_4/inc/ElectrischeMotor.h | 16 ++ Opdracht_4/inc/Machine.cpp | 1 + Opdracht_4/inc/Machine.h | 19 ++ Opdracht_4/inc/MachineImpl.cpp | 28 ++ Opdracht_4/inc/MachineImpl.h | 24 ++ Opdracht_4/inc/Mone.h | 10 + Opdracht_4/inc/Motor.h | 14 + Opdracht_4/inc/Mtwo.h | 10 + Opdracht_4/{Observer => inc}/Observer.cpp | 0 Opdracht_4/{Observer => inc}/Observer.h | 0 Opdracht_4/inc/Tsensor.cpp | 1 + Opdracht_4/inc/Tsensor.h | 10 + Opdracht_4/inc/TsensorImpl.cpp | 17 ++ Opdracht_4/inc/TsensorImpl.h | 17 ++ Opdracht_4/inc/UI.cpp | 10 + Opdracht_4/inc/UI.h | 17 ++ Opdracht_4/main.cpp | 22 ++ Opdracht_4/opdracht4.drawio | 262 ++++++++++-------- 42 files changed, 437 insertions(+), 157 deletions(-) delete mode 100644 Opdracht_4/Application/main.cpp delete mode 100644 Opdracht_4/Domein/Machine.cpp delete mode 100644 Opdracht_4/Domein/Machine.h delete mode 100644 Opdracht_4/Domein/Mone.cpp delete mode 100644 Opdracht_4/Domein/Mone.h delete mode 100644 Opdracht_4/Domein/Motor.cpp delete mode 100644 Opdracht_4/Domein/Motor.h delete mode 100644 Opdracht_4/Domein/Mtwo.cpp delete mode 100644 Opdracht_4/Domein/Mtwo.h delete mode 100644 Opdracht_4/Domein/Sensor.cpp delete mode 100644 Opdracht_4/Domein/Sensor.h delete mode 100644 Opdracht_4/DomeinImplementatie/MachineImpl.cpp delete mode 100644 Opdracht_4/DomeinImplementatie/MachineImpl.h delete mode 100644 Opdracht_4/DomeinImplementatie/MoneImpl.cpp delete mode 100644 Opdracht_4/DomeinImplementatie/MtwoImpl.cpp delete mode 100644 Opdracht_4/DomeinImplementatie/MtwoImpl.h delete mode 100644 Opdracht_4/DomeinImplementatie/SensorImpl.cpp delete mode 100644 Opdracht_4/DomeinImplementatie/SensorImpl.h delete mode 100644 Opdracht_4/UserInterface/UI.cpp delete mode 100644 Opdracht_4/UserInterface/UI.h create mode 100644 Opdracht_4/inc/DieselMotor.cpp create mode 100644 Opdracht_4/inc/DieselMotor.h create mode 100644 Opdracht_4/inc/ElectrischeMotor.cpp create mode 100644 Opdracht_4/inc/ElectrischeMotor.h create mode 100644 Opdracht_4/inc/Machine.cpp create mode 100644 Opdracht_4/inc/Machine.h create mode 100644 Opdracht_4/inc/MachineImpl.cpp create mode 100644 Opdracht_4/inc/MachineImpl.h create mode 100644 Opdracht_4/inc/Mone.h create mode 100644 Opdracht_4/inc/Motor.h create mode 100644 Opdracht_4/inc/Mtwo.h rename Opdracht_4/{Observer => inc}/Observer.cpp (100%) rename Opdracht_4/{Observer => inc}/Observer.h (100%) create mode 100644 Opdracht_4/inc/Tsensor.cpp create mode 100644 Opdracht_4/inc/Tsensor.h create mode 100644 Opdracht_4/inc/TsensorImpl.cpp create mode 100644 Opdracht_4/inc/TsensorImpl.h create mode 100644 Opdracht_4/inc/UI.cpp create mode 100644 Opdracht_4/inc/UI.h create mode 100644 Opdracht_4/main.cpp diff --git a/Opdracht_4/Application/main.cpp b/Opdracht_4/Application/main.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/Opdracht_4/Domein/Machine.cpp b/Opdracht_4/Domein/Machine.cpp deleted file mode 100644 index 8b84790..0000000 --- a/Opdracht_4/Domein/Machine.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "Machine.h" \ No newline at end of file diff --git a/Opdracht_4/Domein/Machine.h b/Opdracht_4/Domein/Machine.h deleted file mode 100644 index a4a5ead..0000000 --- a/Opdracht_4/Domein/Machine.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef __Machine_H -#define __Machine_H - -#endif __Machine_H \ No newline at end of file diff --git a/Opdracht_4/Domein/Mone.cpp b/Opdracht_4/Domein/Mone.cpp deleted file mode 100644 index 604f1fc..0000000 --- a/Opdracht_4/Domein/Mone.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "Mone.h" \ No newline at end of file diff --git a/Opdracht_4/Domein/Mone.h b/Opdracht_4/Domein/Mone.h deleted file mode 100644 index c97a941..0000000 --- a/Opdracht_4/Domein/Mone.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef __Mone_H -#define __Mone_H - -#endif \ No newline at end of file diff --git a/Opdracht_4/Domein/Motor.cpp b/Opdracht_4/Domein/Motor.cpp deleted file mode 100644 index 176ddcb..0000000 --- a/Opdracht_4/Domein/Motor.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "Motor.h" \ No newline at end of file diff --git a/Opdracht_4/Domein/Motor.h b/Opdracht_4/Domein/Motor.h deleted file mode 100644 index 3b7345b..0000000 --- a/Opdracht_4/Domein/Motor.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef __Motor_H -#define __Observer_H - -#endif \ No newline at end of file diff --git a/Opdracht_4/Domein/Mtwo.cpp b/Opdracht_4/Domein/Mtwo.cpp deleted file mode 100644 index 80d7c93..0000000 --- a/Opdracht_4/Domein/Mtwo.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "Mtwo.h" \ No newline at end of file diff --git a/Opdracht_4/Domein/Mtwo.h b/Opdracht_4/Domein/Mtwo.h deleted file mode 100644 index ac4c7dd..0000000 --- a/Opdracht_4/Domein/Mtwo.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef __Mtwo_H -#define __Mtwo_H - -#endif \ No newline at end of file diff --git a/Opdracht_4/Domein/Sensor.cpp b/Opdracht_4/Domein/Sensor.cpp deleted file mode 100644 index 4d11d15..0000000 --- a/Opdracht_4/Domein/Sensor.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "Sensor.h" \ No newline at end of file diff --git a/Opdracht_4/Domein/Sensor.h b/Opdracht_4/Domein/Sensor.h deleted file mode 100644 index 9ec98cd..0000000 --- a/Opdracht_4/Domein/Sensor.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef __Sensor_H -#define __Sensor_H - -#endif \ No newline at end of file diff --git a/Opdracht_4/DomeinImplementatie/MachineImpl.cpp b/Opdracht_4/DomeinImplementatie/MachineImpl.cpp deleted file mode 100644 index a79a8f7..0000000 --- a/Opdracht_4/DomeinImplementatie/MachineImpl.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "MachineImpl.h" \ No newline at end of file diff --git a/Opdracht_4/DomeinImplementatie/MachineImpl.h b/Opdracht_4/DomeinImplementatie/MachineImpl.h deleted file mode 100644 index d11b516..0000000 --- a/Opdracht_4/DomeinImplementatie/MachineImpl.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef __MachioneImpl_H -#define __MachineImpl_H - -#endif \ No newline at end of file diff --git a/Opdracht_4/DomeinImplementatie/MoneImpl.cpp b/Opdracht_4/DomeinImplementatie/MoneImpl.cpp deleted file mode 100644 index b4ba569..0000000 --- a/Opdracht_4/DomeinImplementatie/MoneImpl.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "MoneImpl.h" \ No newline at end of file diff --git a/Opdracht_4/DomeinImplementatie/MoneImpl.h b/Opdracht_4/DomeinImplementatie/MoneImpl.h index fc5be1a..45a8e4a 100644 --- a/Opdracht_4/DomeinImplementatie/MoneImpl.h +++ b/Opdracht_4/DomeinImplementatie/MoneImpl.h @@ -1,4 +1,17 @@ #ifndef __MoneImpl_H #define __MoneImpl_H +#include "Domein/Mone.h" + + +class MoneImpl : public Mone{ +private: + Tsensor* t1; +public: + MoneImpl(Tsensor*); + virtual void start(); + virtual void stop(); + virtual Tsensor* tsensor(); +}; + #endif \ No newline at end of file diff --git a/Opdracht_4/DomeinImplementatie/MtwoImpl.cpp b/Opdracht_4/DomeinImplementatie/MtwoImpl.cpp deleted file mode 100644 index 2298cd9..0000000 --- a/Opdracht_4/DomeinImplementatie/MtwoImpl.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "MtwoImpl.h" \ No newline at end of file diff --git a/Opdracht_4/DomeinImplementatie/MtwoImpl.h b/Opdracht_4/DomeinImplementatie/MtwoImpl.h deleted file mode 100644 index 06c7267..0000000 --- a/Opdracht_4/DomeinImplementatie/MtwoImpl.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef __MtwoImpl_H -#define __MtwoImpl_H - -#endif \ No newline at end of file diff --git a/Opdracht_4/DomeinImplementatie/SensorImpl.cpp b/Opdracht_4/DomeinImplementatie/SensorImpl.cpp deleted file mode 100644 index d31d6bb..0000000 --- a/Opdracht_4/DomeinImplementatie/SensorImpl.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "SensorImpl.h" \ No newline at end of file diff --git a/Opdracht_4/DomeinImplementatie/SensorImpl.h b/Opdracht_4/DomeinImplementatie/SensorImpl.h deleted file mode 100644 index 933b36f..0000000 --- a/Opdracht_4/DomeinImplementatie/SensorImpl.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef __SensorImpl_H -#define __SensorImpl_H - -#endif \ No newline at end of file diff --git a/Opdracht_4/UserInterface/UI.cpp b/Opdracht_4/UserInterface/UI.cpp deleted file mode 100644 index b418007..0000000 --- a/Opdracht_4/UserInterface/UI.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "UI.h" \ No newline at end of file diff --git a/Opdracht_4/UserInterface/UI.h b/Opdracht_4/UserInterface/UI.h deleted file mode 100644 index 2464a20..0000000 --- a/Opdracht_4/UserInterface/UI.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef __UI_H -#define __UI_H - -#endif \ No newline at end of file diff --git a/Opdracht_4/inc/DieselMotor.cpp b/Opdracht_4/inc/DieselMotor.cpp new file mode 100644 index 0000000..db02a9f --- /dev/null +++ b/Opdracht_4/inc/DieselMotor.cpp @@ -0,0 +1,20 @@ +#include "DieselMotor.h" +#include "Tsensor.h" +#include + +DieselMotor::DieselMotor(Tsensor* t): t1(t){ + +} + +Tsensor* DieselMotor::tsensor(){ + return t1; +} + +void DieselMotor::start(){ + std::cout <<"Diesel motor has started"< + +ElectrischeMotor::ElectrischeMotor(Tsensor* t): t1(t){ + +} + +Tsensor* ElectrischeMotor::tsensor(){ + return t1; +} + +void ElectrischeMotor::start(){ + std::cout <<"Elektrische motor has started"<tsensor(); + t1->read(); + m1->start(); + t2 = m2->tsensor(); + t2->read(); + m2->start(); +} + +void MachineImpl::halt(){ + m1->stop(); + m2->stop(); +} + +Motor* MachineImpl::motor1(){ + return m1; +} + +Motor* MachineImpl::motor2(){ + return m2; +} \ No newline at end of file diff --git a/Opdracht_4/inc/MachineImpl.h b/Opdracht_4/inc/MachineImpl.h new file mode 100644 index 0000000..c22e93b --- /dev/null +++ b/Opdracht_4/inc/MachineImpl.h @@ -0,0 +1,24 @@ +#ifndef __MachioneImpl_H +#define __MachineImpl_H + +#include "Machine.h" + +class Tsensor; + +class MachineImpl : public Machine +{ + private: + Tsensor* t1; + Tsensor* t2; + Motor* m1; + Motor* m2; + public: + MachineImpl(Motor*,Motor*); + ~MachineImpl(){}; + virtual Motor* motor1(); + virtual Motor* motor2(); + virtual void run(); + virtual void halt(); +}; + +#endif diff --git a/Opdracht_4/inc/Mone.h b/Opdracht_4/inc/Mone.h new file mode 100644 index 0000000..ac267d3 --- /dev/null +++ b/Opdracht_4/inc/Mone.h @@ -0,0 +1,10 @@ +#ifndef __Mone_H +#define __Mone_H + +#include "Motor.h" + +class Mone : public Motor{ + +}; + +#endif \ No newline at end of file diff --git a/Opdracht_4/inc/Motor.h b/Opdracht_4/inc/Motor.h new file mode 100644 index 0000000..d59480b --- /dev/null +++ b/Opdracht_4/inc/Motor.h @@ -0,0 +1,14 @@ +#ifndef __Motor_H +#define __Motor_H + +class Tsensor; + +class Motor{ +public: + virtual ~Motor() {}; + virtual Tsensor* tsensor() = 0; + virtual void start() = 0; + virtual void stop() = 0; +}; + +#endif \ No newline at end of file diff --git a/Opdracht_4/inc/Mtwo.h b/Opdracht_4/inc/Mtwo.h new file mode 100644 index 0000000..501c8f5 --- /dev/null +++ b/Opdracht_4/inc/Mtwo.h @@ -0,0 +1,10 @@ +#ifndef __Mtwo_H +#define __Mtwo_H + +#include "Motor.h" + +class Mtwo : public Motor{ + +}; + +#endif \ No newline at end of file diff --git a/Opdracht_4/Observer/Observer.cpp b/Opdracht_4/inc/Observer.cpp similarity index 100% rename from Opdracht_4/Observer/Observer.cpp rename to Opdracht_4/inc/Observer.cpp diff --git a/Opdracht_4/Observer/Observer.h b/Opdracht_4/inc/Observer.h similarity index 100% rename from Opdracht_4/Observer/Observer.h rename to Opdracht_4/inc/Observer.h diff --git a/Opdracht_4/inc/Tsensor.cpp b/Opdracht_4/inc/Tsensor.cpp new file mode 100644 index 0000000..b40c5c8 --- /dev/null +++ b/Opdracht_4/inc/Tsensor.cpp @@ -0,0 +1 @@ +#include "Tsensor.h" \ No newline at end of file diff --git a/Opdracht_4/inc/Tsensor.h b/Opdracht_4/inc/Tsensor.h new file mode 100644 index 0000000..263056a --- /dev/null +++ b/Opdracht_4/inc/Tsensor.h @@ -0,0 +1,10 @@ +#ifndef __Sensor_H +#define __Sensor_H + +class Tsensor{ +public: + virtual ~Tsensor(){}; + virtual void read() = 0; + virtual int temperature() = 0; +}; +#endif \ No newline at end of file diff --git a/Opdracht_4/inc/TsensorImpl.cpp b/Opdracht_4/inc/TsensorImpl.cpp new file mode 100644 index 0000000..ffd9c8a --- /dev/null +++ b/Opdracht_4/inc/TsensorImpl.cpp @@ -0,0 +1,17 @@ +#include "TsensorImpl.h" +#include + +TsensorImpl::TsensorImpl(): temperatuur(0){ + +} + +void TsensorImpl::read(){ + std::cout << "Voer een temperatuur in: "; + std::cin >> temperatuur; + std::cout << endl; + notify(); +} + +int TsensorImpl::temperature(){ + return temperatuur; +} \ No newline at end of file diff --git a/Opdracht_4/inc/TsensorImpl.h b/Opdracht_4/inc/TsensorImpl.h new file mode 100644 index 0000000..3d48681 --- /dev/null +++ b/Opdracht_4/inc/TsensorImpl.h @@ -0,0 +1,17 @@ +#ifndef __TsensorImpl_H +#define __TsensorImpl_H + +#include "Tsensor.h" +#include "Observer.h" + +class TsensorImpl : public Tsensor, public Subject{ + private: + int temperatuur; + public: + TsensorImpl(); + virtual ~TsensorImpl(){}; + virtual void read(); + virtual int temperature(); +}; + +#endif \ No newline at end of file diff --git a/Opdracht_4/inc/UI.cpp b/Opdracht_4/inc/UI.cpp new file mode 100644 index 0000000..89c9db7 --- /dev/null +++ b/Opdracht_4/inc/UI.cpp @@ -0,0 +1,10 @@ +#include "UI.h" +#include "TsensorImpl.h" + +#include + +using namespace std; + +UI::UI(TsensorImpl* t) : Observer(t){} + +void UI::update() {cout << dynamic_cast(getSubject())->temperature() << endl;} diff --git a/Opdracht_4/inc/UI.h b/Opdracht_4/inc/UI.h new file mode 100644 index 0000000..ac4f292 --- /dev/null +++ b/Opdracht_4/inc/UI.h @@ -0,0 +1,17 @@ +#ifndef __UI_H +#define __UI_H + +class TsensorImpl; + +#include "Observer.h" + +class UI : public Observer{ +private: + TsensorImpl* t; +public: + UI(TsensorImpl*); + virtual ~UI(){}; + virtual void update(); +}; + +#endif \ No newline at end of file diff --git a/Opdracht_4/main.cpp b/Opdracht_4/main.cpp new file mode 100644 index 0000000..272e8c5 --- /dev/null +++ b/Opdracht_4/main.cpp @@ -0,0 +1,22 @@ +#include "inc/MachineImpl.h" +#include "inc/DieselMotor.h" +#include "inc/ElectrischeMotor.h" +#include "inc/TsensorImpl.h" +#include "inc/UI.h" + +int main (){ + TsensorImpl* t1 = new TsensorImpl(); + TsensorImpl* t2 = new TsensorImpl(); + + DieselMotor* diesel = new DieselMotor(t1); + ElectrischeMotor* elec = new ElectrischeMotor(t2); + + UI* interface1 = new UI(t1); + UI* interface2 = new UI(t2); + + MachineImpl* machine = new MachineImpl(diesel, elec); + + machine->run(); + machine->halt(); + return 0; +} \ No newline at end of file diff --git a/Opdracht_4/opdracht4.drawio b/Opdracht_4/opdracht4.drawio index dc86da7..a6bbc7c 100644 --- a/Opdracht_4/opdracht4.drawio +++ b/Opdracht_4/opdracht4.drawio @@ -1,19 +1,19 @@ - + - - + + - - + + - + @@ -25,13 +25,6 @@ - - - - - - - @@ -43,9 +36,6 @@ - - - @@ -55,62 +45,74 @@ + + + + + + + + + - + - + - + - + - + - + - + - + - + - - + + - - + + - - + + - + + + + - + @@ -119,102 +121,96 @@ - + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - - + + - - + + - - - - - - - + @@ -223,7 +219,7 @@ - + @@ -233,7 +229,7 @@ - + @@ -242,90 +238,72 @@ - - - - - - - + - - + + - + - - - - - - - - - - - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -333,32 +311,94 @@ - + - + - + - + - + - + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +