Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created January 4, 2018 16:30
Show Gist options
  • Save tommcfarlin/ff0bd4e2b7ceaebc957342dd41b7709e to your computer and use it in GitHub Desktop.
Save tommcfarlin/ff0bd4e2b7ceaebc957342dd41b7709e to your computer and use it in GitHub Desktop.
[OOP Interfaces] Object-Oriented Programming: Understanding Interfaces
<?php
class Cache
{
public function set($key, $value)
{
// method implementation
}
}
<?php
class Cache
{
public function set($key, $value) {
set_transient($key, $value);
}
}
<?php
interface iCache
{
public function set($key, $value);
public function get($key);
public function has($key);
}
<?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