Skip to content

Instantly share code, notes, and snippets.

Avatar

mcsee mcsee

View GitHub Profile
View declarativeFlag.php
<?
function dummy()
{
$atLeastOneElementWasFound = true;
while (!$atLeastOneElementWasFound) {
$elementSatisfies = doSomething();
if ($elementSatisfies) {
View uselessFlag.php
<?
function dummy() {
$flag = true;
while ($flag == true) {
$result = doSomething();
if ($result){
View coupled.java
public class MyCollection {
public bool HasNext { get; set;} //implementation details
public object Next(); ////implementation details
}
public class MyDomainObject sum(MyCollection anObjectThatCanBeIterated) {
//Tight coupling
}
//cannot fake or mock this method since it always expects an instance of MyCollection
View decoupled.java
public interface Iterator {
public bool HasNext { get; set;}
public object Next();
}
public Iterator Reverse(Iterator iterator) {
var list = new List<int>();
while (iterator.HasNext) {
list.Insert(0, iterator.Next());
}
View namespaces.php
<?
namespace Date;
final class :DateFormatter {
function reformatYYYYDDMMtoYYYYMMDD($date) {
}
//function is not static since class single responsibility is to create instances and not be a library of utils
View globalClasses.php
<?
class StringUtilHelper {
static function reformatYYYYDDMMtoYYYYMMDD($date) {
}
}
class Singleton {
View decorated.php
<?
final class Calculator {
function computeSomething() {
// Do Real work here since I am Compute!
}
}
//Clean and cohesive class, single responsibility
View wrapper.php
<?
final class Calculator {
private $cachedResults;
function computeSomething() {
if (isset($this->cachedResults)) {
return $this->cachedResults;
}
View composition.php
<?
interface ControllerInterface {
}
abstract class Controller implements ControllerInterface {
}
View hierarchy.php
<?
abstract class Controller {
}
class BaseController extends Controller {
}