-
-
Save tommcfarlin/ff0bd4e2b7ceaebc957342dd41b7709e to your computer and use it in GitHub Desktop.
[OOP Interfaces] Object-Oriented Programming: Understanding Interfaces
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 | |
class Cache | |
{ | |
public function set($key, $value) | |
{ | |
// method implementation | |
} | |
} |
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 | |
class Cache | |
{ | |
public function set($key, $value) { | |
set_transient($key, $value); | |
} | |
} |
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 | |
interface iCache | |
{ | |
public function set($key, $value); | |
public function get($key); | |
public function has($key); | |
} |
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 | |
interface iCache { | |
public function set($key, $value); | |
public function get($key); | |
public function has($key); | |
} | |
public class SimpleCache implemnents iCache | |
{ | |
public function set($key, $value) | |
{ | |
set_transient($key, $value, DAY_IN_SECONDS); | |
} | |
public function get($key) | |
{ | |
if (!$this->has($key)) | |
{ | |
return false; | |
} | |
return get_transient($key); | |
} | |
public function has($key) | |
{ | |
return false !== get_transient($key); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment