From 82740e955bbee4214a4265a21fe183b01d787009 Mon Sep 17 00:00:00 2001 From: sjuergen Date: Tue, 14 Jan 2025 16:54:33 +0100 Subject: [PATCH] rework oop5 --- .../3_calculator_current_volume/README.md | 12 +++---- .../4_inheritance_complex_valve/apax.yml | 4 ++- .../4_inheritance_complex_valve/src/ITank.st | 25 --------------- .../4_inheritance_complex_valve/src/IValve.st | 10 ------ .../src/ItfTank.st | 15 +++++++++ .../src/ItfValve.st | 14 ++++++++ .../src/TankBase.st | 32 +++++++++++++++++++ .../src/TankWithVolume.st | 10 +++--- .../src/{basicValve.st => ValveBase.st} | 10 ++++-- .../src/configuration.st | 4 +-- .../src/program.st | 5 ++- 11 files changed, 87 insertions(+), 54 deletions(-) delete mode 100644 05_oop_in_st/exercises/4_inheritance_complex_valve/src/ITank.st delete mode 100644 05_oop_in_st/exercises/4_inheritance_complex_valve/src/IValve.st create mode 100644 05_oop_in_st/exercises/4_inheritance_complex_valve/src/ItfTank.st create mode 100644 05_oop_in_st/exercises/4_inheritance_complex_valve/src/ItfValve.st create mode 100644 05_oop_in_st/exercises/4_inheritance_complex_valve/src/TankBase.st rename 05_oop_in_st/exercises/4_inheritance_complex_valve/src/{basicValve.st => ValveBase.st} (87%) diff --git a/05_oop_in_st/exercises/3_calculator_current_volume/README.md b/05_oop_in_st/exercises/3_calculator_current_volume/README.md index a2ebc12..9af1de2 100644 --- a/05_oop_in_st/exercises/3_calculator_current_volume/README.md +++ b/05_oop_in_st/exercises/3_calculator_current_volume/README.md @@ -9,7 +9,7 @@ Using the solution for the HandsOn2 as the starting point: >* **FIRST:** Create a TYPE for the Tank State as the Valve one. ->* **SECOND:** Create a second class: *TankWithVolume* that implements also the interface *ITank* created in the HandsOn2. +>* **SECOND:** Create a second class: *TankWithVolume* that implements also the interface *ItfTank* created in the HandsOn2. >* **THIRD:** Create a program that calculates and displays as an output the current volume of the tank . @@ -18,11 +18,11 @@ Using the solution for the HandsOn2 as the starting point: ### TYPE for Tank State |Status| - |-| - |Filling| - |Emptying| - |Flushing| - |Closed| +|-| +|Filling| +|Emptying| +|Flushing| +|Closed| **Advice:** remember that the starting state is closed and you should include it on the definition. diff --git a/05_oop_in_st/exercises/4_inheritance_complex_valve/apax.yml b/05_oop_in_st/exercises/4_inheritance_complex_valve/apax.yml index 92d1b64..9ec7b30 100644 --- a/05_oop_in_st/exercises/4_inheritance_complex_valve/apax.yml +++ b/05_oop_in_st/exercises/4_inheritance_complex_valve/apax.yml @@ -1,7 +1,7 @@ # General information name: "oop1" version: 0.0.1 -type: lib +type: app keywords: - library author: SIMATIC AX @@ -26,3 +26,5 @@ variables: # Files, which will be shipped with the library files: - bin +dependencies: + "@ax/system-timer": ^8.0.7 diff --git a/05_oop_in_st/exercises/4_inheritance_complex_valve/src/ITank.st b/05_oop_in_st/exercises/4_inheritance_complex_valve/src/ITank.st deleted file mode 100644 index c8b5527..0000000 --- a/05_oop_in_st/exercises/4_inheritance_complex_valve/src/ITank.st +++ /dev/null @@ -1,25 +0,0 @@ -NAMESPACE FluidHandlingInterfaces - INTERFACE ITank - - METHOD OpenInlet - END_METHOD - METHOD OpenOutlet - END_METHOD - METHOD CloseInlet - END_METHOD - METHOD CloseOutlet - END_METHOD - - METHOD Fill - END_METHOD - METHOD Flush - END_METHOD - - METHOD Close - END_METHOD - - METHOD Emptying - END_METHOD - - END_INTERFACE -END_NAMESPACE \ No newline at end of file diff --git a/05_oop_in_st/exercises/4_inheritance_complex_valve/src/IValve.st b/05_oop_in_st/exercises/4_inheritance_complex_valve/src/IValve.st deleted file mode 100644 index 79a525a..0000000 --- a/05_oop_in_st/exercises/4_inheritance_complex_valve/src/IValve.st +++ /dev/null @@ -1,10 +0,0 @@ -NAMESPACE FluidHandlingClass - INTERFACE IValve - METHOD Open - END_METHOD - METHOD Close - END_METHOD - METHOD GetState : ValveState - END_METHOD - END_INTERFACE -END_NAMESPACE \ No newline at end of file diff --git a/05_oop_in_st/exercises/4_inheritance_complex_valve/src/ItfTank.st b/05_oop_in_st/exercises/4_inheritance_complex_valve/src/ItfTank.st new file mode 100644 index 0000000..3f951ad --- /dev/null +++ b/05_oop_in_st/exercises/4_inheritance_complex_valve/src/ItfTank.st @@ -0,0 +1,15 @@ +//File to create the interface to implement the class tank +NAMESPACE FluidHandlingClass + + INTERFACE ItfTank + METHOD Fill + END_METHOD + METHOD Flush + END_METHOD + METHOD Close + END_METHOD + METHOD Emptying + END_METHOD + END_INTERFACE + +END_NAMESPACE diff --git a/05_oop_in_st/exercises/4_inheritance_complex_valve/src/ItfValve.st b/05_oop_in_st/exercises/4_inheritance_complex_valve/src/ItfValve.st new file mode 100644 index 0000000..292c6bc --- /dev/null +++ b/05_oop_in_st/exercises/4_inheritance_complex_valve/src/ItfValve.st @@ -0,0 +1,14 @@ +//File to create the interface to implement the class valve +//File to create the interface to implement the class tank +NAMESPACE FluidHandlingClass + + INTERFACE ItfValve + METHOD Open + END_METHOD + METHOD Close + END_METHOD + METHOD GetState : ValveState + END_METHOD + END_INTERFACE + +END_NAMESPACE diff --git a/05_oop_in_st/exercises/4_inheritance_complex_valve/src/TankBase.st b/05_oop_in_st/exercises/4_inheritance_complex_valve/src/TankBase.st new file mode 100644 index 0000000..c0420b1 --- /dev/null +++ b/05_oop_in_st/exercises/4_inheritance_complex_valve/src/TankBase.st @@ -0,0 +1,32 @@ +//Use the same namespace than the TYPE for the Valves state + +NAMESPACE FluidHandlingClass + + CLASS TankBase IMPLEMENTS ItfTank + VAR PRIVATE + inletValve: ValveBase; + outletValve: ValveBase; + END_VAR + + METHOD PUBLIC Fill + inletValve.Open(); + outletValve.Close(); + END_METHOD + + METHOD PUBLIC Flush + inletValve.Open(); + outletValve.Open(); + END_METHOD + + METHOD PUBLIC Close + inletValve.Close(); + outletValve.Close(); + END_METHOD + + METHOD PUBLIC Emptying + this.Close(); + outletValve.Open(); + END_METHOD + END_CLASS + +END_NAMESPACE \ No newline at end of file diff --git a/05_oop_in_st/exercises/4_inheritance_complex_valve/src/TankWithVolume.st b/05_oop_in_st/exercises/4_inheritance_complex_valve/src/TankWithVolume.st index eae50f3..69b53e7 100644 --- a/05_oop_in_st/exercises/4_inheritance_complex_valve/src/TankWithVolume.st +++ b/05_oop_in_st/exercises/4_inheritance_complex_valve/src/TankWithVolume.st @@ -1,8 +1,10 @@ -NAMESPACE FluidHandlingInterfaces - CLASS TankWithVolume IMPLEMENTS ITank +USING FluidHandlingClass; + +NAMESPACE FluidHandlingClass + CLASS TankWithVolume IMPLEMENTS ItfTank VAR PUBLIC - inletValve: IValve; - outletValve: IValve; + inletValve: ItfValve; + outletValve: ItfValve; volume: REAL; END_VAR VAR PROTECTED diff --git a/05_oop_in_st/exercises/4_inheritance_complex_valve/src/basicValve.st b/05_oop_in_st/exercises/4_inheritance_complex_valve/src/ValveBase.st similarity index 87% rename from 05_oop_in_st/exercises/4_inheritance_complex_valve/src/basicValve.st rename to 05_oop_in_st/exercises/4_inheritance_complex_valve/src/ValveBase.st index 8d7a9a4..dc3b099 100644 --- a/05_oop_in_st/exercises/4_inheritance_complex_valve/src/basicValve.st +++ b/05_oop_in_st/exercises/4_inheritance_complex_valve/src/ValveBase.st @@ -1,5 +1,8 @@ -NAMESPACE FluidHandlingClass - CLASS basicValve IMPLEMENTS IValve +//Use the same namespace than the TYPE for the Valves state + +NAMESPACE FluidHandlingClass + + CLASS ValveBase IMPLEMENTS ItfValve VAR _ctrlOpen : BOOL; _state : ValveState; @@ -41,4 +44,5 @@ NAMESPACE FluidHandlingClass state := _state; END_METHOD END_CLASS -END_NAMESPACE + +END_NAMESPACE \ No newline at end of file diff --git a/05_oop_in_st/exercises/4_inheritance_complex_valve/src/configuration.st b/05_oop_in_st/exercises/4_inheritance_complex_valve/src/configuration.st index 01f84e7..8e1270c 100644 --- a/05_oop_in_st/exercises/4_inheritance_complex_valve/src/configuration.st +++ b/05_oop_in_st/exercises/4_inheritance_complex_valve/src/configuration.st @@ -5,8 +5,8 @@ CONFIGURATION MyConfiguration VAR_GLOBAL //FIRST IMPLEMENTATION SIMPLE - vIn : basicValve; - vOut: basicValveValve; + vIn : ValveBase; + vOut: ValveBase; tank : TankWithVolume := (inletValve := vIn, outletValve := vOut, volume := 100); diff --git a/05_oop_in_st/exercises/4_inheritance_complex_valve/src/program.st b/05_oop_in_st/exercises/4_inheritance_complex_valve/src/program.st index 876f8c0..cc4df4e 100644 --- a/05_oop_in_st/exercises/4_inheritance_complex_valve/src/program.st +++ b/05_oop_in_st/exercises/4_inheritance_complex_valve/src/program.st @@ -5,8 +5,8 @@ USING System.Timer; PROGRAM CalculatorCurrentVolume VAR_EXTERNAL - vIn : Valve2; - vOut : Valve2; + vIn : ValveBase; + vOut : ValveBase; tank : TankWithVolume; vInCtrl : BOOL; @@ -106,7 +106,6 @@ PROGRAM CalculatorCurrentVolume IF current_volume < 0 THEN current_volume := 0; // //Ensure volume does not exceed the minimum volume END_IF; - END_IF; capacity_percentage := tank.Capacity(currentVolume := current_volume);; //Actualize the capacity percentage _ton.signal := TRUE; // Reinitialize the timer END_IF;