Skip to content

Commit

Permalink
rework oop5
Browse files Browse the repository at this point in the history
  • Loading branch information
sjuergen committed Jan 14, 2025
1 parent 34b07c7 commit 82740e9
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 54 deletions.
12 changes: 6 additions & 6 deletions 05_oop_in_st/exercises/3_calculator_current_volume/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 .

Expand All @@ -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.

Expand Down
4 changes: 3 additions & 1 deletion 05_oop_in_st/exercises/4_inheritance_complex_valve/apax.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# General information
name: "oop1"
version: 0.0.1
type: lib
type: app
keywords:
- library
author: SIMATIC AX
Expand All @@ -26,3 +26,5 @@ variables:
# Files, which will be shipped with the library
files:
- bin
dependencies:
"@ax/system-timer": ^8.0.7
25 changes: 0 additions & 25 deletions 05_oop_in_st/exercises/4_inheritance_complex_valve/src/ITank.st

This file was deleted.

10 changes: 0 additions & 10 deletions 05_oop_in_st/exercises/4_inheritance_complex_valve/src/IValve.st

This file was deleted.

15 changes: 15 additions & 0 deletions 05_oop_in_st/exercises/4_inheritance_complex_valve/src/ItfTank.st
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions 05_oop_in_st/exercises/4_inheritance_complex_valve/src/ItfValve.st
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions 05_oop_in_st/exercises/4_inheritance_complex_valve/src/TankBase.st
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -41,4 +44,5 @@ NAMESPACE FluidHandlingClass
state := _state;
END_METHOD
END_CLASS
END_NAMESPACE

END_NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ USING System.Timer;

PROGRAM CalculatorCurrentVolume
VAR_EXTERNAL
vIn : Valve2;
vOut : Valve2;
vIn : ValveBase;
vOut : ValveBase;
tank : TankWithVolume;

vInCtrl : BOOL;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 82740e9

Please sign in to comment.