View Account.js
const addEntry = Symbol('addEntry'), | |
getBalance = Symbol('getBalance'); | |
export default class Account { | |
constructor(ledgers) { | |
const roles = { | |
ledgers: { | |
[addEntry](message, amount) { | |
ledgers.push(new LedgerEntry(message, amount)); | |
}, |
View dci.php
/* | |
This is just a demo to show the concept. For a full implementation, | |
see https://github.com/mbrowne/dci-php | |
*/ | |
trait RolePlayer | |
{ | |
private $roles = []; | |
private $roleMethods = []; |
View CustomError.js
function CustomError(message) { | |
if (!(this instanceof CustomError)) { | |
throw new TypeError("Constructor 'CustomError' cannot be invoked without 'new'"); | |
} | |
var err; | |
if (Object.setPrototypeOf) { | |
err = new Error(message); | |
Object.setPrototypeOf(err, CustomError.prototype); | |
} |
View TransferMoney.swift
//TransferMoney context | |
class TransferMoney: Context { | |
private let SourceAccount: SourceAccountRole | |
private let DestinationAccount: DestinationAccountRole | |
init(source:AccountData, destination:AccountData) { | |
SourceAccount = source as! SourceAccountRole | |
DestinationAccount = destination as! DestinationAccountRole |
View TransferMoney.ts
/** | |
* Transfer Money use case | |
*/ | |
function TransferMoney(sourceAcct: Account, destinationAcct: Account, amount: number) { | |
//bind the objects to their roles | |
SourceAccount <- sourceAcct; | |
DestinationAccount <- destinationAcct; | |
Amount <- amount; | |
View prototypal.js
var Animal = { | |
init: function(name) { | |
this.name = name || null; | |
} | |
} | |
var Cat = Object.create(Animal); | |
Cat.meow = function() { | |
console.log('meow'); | |
} |
View db-sync.sh
#!/bin/bash | |
#SYNC MONGODB DATABASE FROM REMOTE SERVER | |
#NOTE: This overwrites the local copy of the database | |
remoteHost='yourhost.com' | |
remoteDbUser='root' | |
remoteDbPasswd='password123' | |
remoteDb='test' | |
localDb='test' |
View php5.3.php
<?php | |
namespace UseCases | |
{ | |
class TransferMoney extends \DCI\Context | |
{ | |
//These would ideally be private but they need to be public so that the roles can access them, | |
//since PHP doesn't support inner classes | |
public $sourceAccount; | |
public $destinationAccount; |
View Role.php
<?php | |
namespace DCI; | |
/** | |
* DCI Role base class | |
*/ | |
abstract class Role | |
{ | |
/** | |
* The data object playing this role (the RolePlayer). |
View simpleoo.js
(function(define) { | |
/* | |
Example usage: | |
function Animal() {} | |
Animal.prototype.eat = function() { console.log('yum'); } | |
function Cat() {} | |
simpleoo(Cat).extend(Animal, { | |
meow: function() { console.log('meow'); } |
NewerOlder