This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Human { | |
private Heart heart; | |
private Brain brain; | |
private Legs legs; | |
public Distance walk(Place origin, Place destination) throws UnreachableDestinationException { | |
//some code | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fa = persons.FitnessAddict( | |
"Bar", | |
"Baz", | |
new Date(1990,5,5), | |
80, | |
1.8) | |
fa.isWeightNormal() // true | |
fa.saySomething() // "bar" | |
fa.name() // "Bar Baz" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//persons module | |
persons = (function(){ | |
//private Person object constructor | |
var Person = function(firstName, lastName, birthDate){ | |
var foo = "bar"; | |
var name = function(){ | |
return firstName + " " + lastName; | |
} |
NewerOlder