Skip to content

Instantly share code, notes, and snippets.

View wsoczynski's full-sized avatar

Wojciech Soczyński wsoczynski

  • London, United Kingdom
View GitHub Profile
@wsoczynski
wsoczynski / gist:2127019
Created March 19, 2012 20:52
The Context 7
class Human(
protected[Human] val legsObj: Legs,
protected[Human] val heartObj: Heart,
protected[Human] val brainObj: Brain) {
def this(human: Human) = {
this(human.legsObj, human.heartObj, human.brainObj)
}
}
@wsoczynski
wsoczynski / gist:2112886
Created March 19, 2012 13:48
The Context 6
public class Main {
public static void main(String[] args) {
Human human = new Human(new Legs(),new Heart(), new Brain());
//let the human walk somewhere
Walker walker = new Walker(human);
walkFromHomeToWork(walker);
//oops! there was an accident when walking
@wsoczynski
wsoczynski / gist:2112816
Created March 19, 2012 13:46
The Context 5
public class Human {
protected Legs legs;
protected Brain brain;
protected Heart heart;
public Human(Legs legs, Heart heart, Brain brain){
this.legs = legs;
this.heart = heart;
this.brain = brain;
@wsoczynski
wsoczynski / theContext3.java
Created December 11, 2011 15:24
The Context 3 - getters and setters
public class Human {
private Heart heart;
private Brain brain;
private Legs legs;
public Distance walk(Place origin, Place destination) throws UnreachableDestinationException {
//some code
}
@wsoczynski
wsoczynski / theContext4.java
Created November 24, 2011 19:57
The Context 4
public class Surgeon {
private HashMap<String, MedicalProcedure> knownProcedures;
Boolean operate(Organ[] organs, String procedureName){
MedicalProcedure procedure = knownProcedures.get(procedureName);
Boolean result = procedure.execute(organs);
return result;
}
}
@wsoczynski
wsoczynski / theContext2.java
Created November 24, 2011 19:07
The Context 2
public class Surgeon {
private HashMap<String, MedicalProcedure> knownProcedures;
public Boolean operate(Human patient, String procedureName) throws FamilyDoesNotAllowException {
Field[] fields = Human.class.getDeclaredFields();
try {
List<Organ> organs = new ArrayList<Organ>();
for (Field field : fields) {
@wsoczynski
wsoczynski / theContext.java
Created November 23, 2011 08:06
The Context
public class Human {
private Legs legs;
private Heart heart;
private Brain brain;
public Human(Heart heart, Brain brain, Legs legs){
this.legs = legs;
this.heart = heart;
this.brain = brain;
@wsoczynski
wsoczynski / noFrameworkJsFramework3.js
Created November 22, 2011 14:41
The no framework JS framework 3
//Comparing two objects based on their behaviour/functions
Object.prototype.behavesAs = function(obj){
for(var name in obj){
var property = obj[name]
if(typeof(property) == "function" && name != "behavesAs"){
if( !(this.hasOwnProperty(name) && typeof(this[name]) == 'function') ){
return false
}
}
@wsoczynski
wsoczynski / noFrameworkJsFramework2.js
Created November 22, 2011 13:01
The no framework JS framework 2
var fa = persons.FitnessAddict(
"Bar",
"Baz",
new Date(1990,5,5),
80,
1.8)
fa.isWeightNormal() // true
fa.saySomething() // "bar"
fa.name() // "Bar Baz"
@wsoczynski
wsoczynski / noFrameworkJsFramework.js
Created November 22, 2011 12:59
The no framework JS framework
//persons module
persons = (function(){
//private Person object constructor
var Person = function(firstName, lastName, birthDate){
var foo = "bar";
var name = function(){
return firstName + " " + lastName;
}