Skip to content

Instantly share code, notes, and snippets.

@nelsonsar
Created September 10, 2015 17:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nelsonsar/23a2fbb6f8dfcb639de2 to your computer and use it in GitHub Desktop.
Save nelsonsar/23a2fbb6f8dfcb639de2 to your computer and use it in GitHub Desktop.
Where traits may be useful
<?php
interface InputStream
{
public function close();
public function read($numberOfBytes);
public function skip($numberOfBytes);
}
interface MarkableStream
{
public function mark();
public function reset();
}
interface OutputStream
{
public function close();
public function write($bytes);
}
trait Closeable
{
public function close()
{
fclose($this->fileDescriptor);
}
}
trait Markable
{
// implement mark and reset behavior
}
class FileInputStream implements InputStream, MarkableStream
{
use Closeable;
use Markable;
//Implement here FileInputStream behavior
}
class FileOutputStream implements OutputStream
{
use Closeable;
//Implement here FileInputStream behavior
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment