Created
March 21, 2023 23:59
-
-
Save mentisy/6f3f8872b9a529c86b1e3eb80c9fc900 to your computer and use it in GitHub Desktop.
Eksempler på OOP i PHP for å sammenligne med Cue Visual Basic
This file contains 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
<?php | |
declare(strict_types=1); | |
namespace App; | |
/** | |
* Cell class | |
* | |
* Abstract class for inheritance | |
*/ | |
abstract class Cell | |
{ | |
/** | |
* Cell ID | |
*/ | |
protected const ID = 0; | |
/** | |
* Set intercom alarm status | |
* | |
* @param bool $status Status. True for start and false for stop | |
* @return void | |
*/ | |
public function ContrMaster_funcCell_eIntercomAlarm(bool $status) | |
{ | |
if ($status) { | |
$this->intercomAlarmStart(); | |
} else { | |
$this->intercomAlarmStop(); | |
} | |
} | |
/** | |
* Start intercom alert | |
* | |
* @return void | |
*/ | |
public function intercomAlarmStart() | |
{ | |
echo "intercom alert start for cell " . static::ID . "\n"; | |
} | |
/** | |
* Stop intercom alert | |
* | |
* @return void | |
*/ | |
public function intercomAlarmStop() | |
{ | |
echo "intercom alert stop for cell " . static::ID . "\n"; | |
} | |
} | |
This file contains 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
<?php | |
declare(strict_types=1); | |
namespace App; | |
class CellFour extends Cell | |
{ | |
/** | |
* Cell ID | |
*/ | |
protected const ID = 4; | |
} |
This file contains 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
<?php | |
declare(strict_types=1); | |
namespace App; | |
class CellOne extends Cell | |
{ | |
/** | |
* Cell ID | |
*/ | |
protected const ID = 1; | |
} |
This file contains 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
<?php | |
declare(strict_types=1); | |
namespace App; | |
class CellThree extends Cell | |
{ | |
/** | |
* Cell ID | |
*/ | |
protected const ID = 3; | |
/** | |
* @inheritDoc | |
*/ | |
public function intercomAlarmStart() | |
{ | |
parent::intercomAlarmStart(); | |
echo "Overriden extra message for cell three\n"; | |
} | |
} |
This file contains 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
<?php | |
declare(strict_types=1); | |
namespace App; | |
class CellTwo extends Cell | |
{ | |
/** | |
* Cell ID | |
*/ | |
protected const ID = 2; | |
/** | |
* Change state of water for toilet | |
* | |
* @param int $state 0: Open, 1: Close, 2: Toggle | |
* @return void | |
*/ | |
public function SetWaterWC(int $state) | |
{ | |
switch ($state) { | |
case 0: echo "open"; | |
case 1: echo "close"; | |
case 2: echo "toggle?"; | |
} | |
} | |
} |
This file contains 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
<?php | |
require 'vendor/autoload.php'; | |
use App\CellFour; | |
use App\CellOne; | |
use App\CellThree; | |
use App\CellTwo; | |
$cellOne = new CellOne(); | |
$cellOne->intercomAlarmStart(); | |
$cellTwo = new CellTwo(); | |
$cellTwo->intercomAlarmStart(); | |
$cellThree = new CellThree(); | |
$cellThree->intercomAlarmStart(); | |
$cellFour = new CellFour(); | |
$cellFour->intercomAlarmStart(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment