Permalink
Browse files

Working on the first pass.

  • Loading branch information...
1 parent 7245761 commit 0e0de36ca9e93aec51d4cf8e0e530dbc0067e3c8 @bennadel committed May 5, 2012
View
@@ -2,11 +2,11 @@
<!DOCTYPE html>
<html>
<head>
- <title>Object Calesthenics In JavaScript</title>
+ <title>Object Calisthenics In JavaScript</title>
<!--
Load the RequireJS and the application bootstrap. Since Object
- Calesthenics requires the creation of small, cohesive classes,
+ Calisthenics requires the creation of small, cohesive classes,
we'll definitely want a beasty class-loader like RequireJS.
-->
<script
@@ -18,7 +18,7 @@
<body>
<h1>
- Object Calesthenics In JavaScript
+ Object Calisthenics In JavaScript
</h1>
</body>
View
@@ -45,6 +45,7 @@ require(
console.log( "Smallest thing working!" );
+
var factory = new Factory();
var m = factory.createMale();
@@ -56,7 +57,6 @@ require(
console.log( m.isAttractedTo( f ) );
console.log( f.isAttractedTo( m ) );
-
}
);
@@ -0,0 +1,28 @@
+
+// Define class requirments and cosntructor.
+define(
+ [
+ "./util/Collection"
+ ],
+ function( Collection ){
+
+ function Blackbook(){
+
+ Collection.apply( this, arguments );
+
+ }
+
+
+ // Extend core collection.
+ Blackbook.prototype = Object.create( Collection.prototype );
+
+
+ // -------------------------------------------------- //
+ // -------------------------------------------------- //
+
+
+ // Return constructor definition.
+ return( Blackbook );
+
+ }
+);
@@ -3,32 +3,30 @@
define(
[
"model/person/Name",
- "model/person/Collection",
"model/person/Person",
"model/person/orientation/FemaleIdentity",
"model/person/orientation/FemalePreference",
"model/person/orientation/MaleIdentity",
"model/person/orientation/MalePreference",
"model/person/orientation/Orientation",
- "model/util/Collection"
+ "model/util/RandomAccessCollection"
],
function(
- Name,
- PersonCollection,
+ Name,
Person,
FemaleIdentity,
FemalePreference,
MaleIdentity,
MalePreference,
Orientation,
- Collection
+ RandomAccessCollection
){
function Factory(){
- this._maleNames = new Collection( "Arnold", "Vin", "Sly", "James", "Robert" );
- this._femaleNames = new Collection( "Tricia", "Sarah", "Joanna", "Kim", "Stacy" );
+ this._maleNames = new RandomAccessCollection( "Arnold", "Vin", "Sly", "James", "Robert" );
+ this._femaleNames = new RandomAccessCollection( "Tricia", "Sarah", "Joanna", "Kim", "Stacy" );
}
@@ -43,8 +41,6 @@ define(
var orientation = new Orientation( identity, preference );
var person = new Person( name, orientation );
- console.log( preference );
-
return( person );
},
@@ -0,0 +1,64 @@
+
+// Define class requirments and cosntructor.
+define(
+ [
+ "./match/MatchCollection",
+ "./match/Match"
+ ],
+ function( MatchCollection ){
+
+
+ function MatchMaker( blackbook ){
+
+ this._blackbook = blackbook;
+
+ }
+
+
+ MatchMaker.prototype = {
+
+ introduce: function( person ){
+
+ this._blackbook.push( person );
+
+ },
+
+
+ suggestMatches: function(){
+
+ var matches = new MatchCollection();
+
+ for (var p1 = 0 ; p1 < this._blackbook.size() ; p1++){
+
+ for (var p2 = 0 ; p2 < this._blackbook.size() ; p2++){
+
+ matches.push(
+ new Match(
+ this._blackbook.get( p1 ),
+ this._blackbook.get( p2 )
+ )
+ );
+
+ }
+
+ }
+
+ matches.removeBadMatches();
+
+ return( matches );
+
+ }
+
+ };
+
+
+ // -------------------------------------------------- //
+ // -------------------------------------------------- //
+
+
+ // Return constructor definition.
+ return( MatchMaker );
+
+
+ }
+);
@@ -0,0 +1,53 @@
+
+// Define class requirments and cosntructor.
+define(
+ [],
+ function(){
+
+
+ function Match( person1, person2 ){
+
+ this._person1 = person1;
+ this._person2 = person2;
+
+ }
+
+
+ Match.prototype = {
+
+ getPerson1: function(){
+
+ return( this._person1 );
+
+ },
+
+
+ getPerson2: function(){
+
+ return( this._person2 );
+
+ },
+
+
+ isPromising: function(){
+
+ return(
+ this._person1.isAttractedTo( this._person2 ) &&
+ this._person2.isAttractedTo( this._person1 )
+ );
+
+ }
+
+ };
+
+
+ // -------------------------------------------------- //
+ // -------------------------------------------------- //
+
+
+ // Return constructor definition.
+ return( Match );
+
+
+ }
+);
@@ -0,0 +1,52 @@
+
+// Define class requirments and cosntructor.
+define(
+ [
+ "../util/Collection"
+ ],
+ function( Collection ){
+
+
+ function MatchCollection(){
+
+ Collection.apply( this, arguments )
+
+ }
+
+
+ MatchCollection.prototype = Object.create( Collection.prototype );
+
+
+ MatchCollection.prototype.removeBadMatches = function(){
+
+ for (var i = this._values.length - 1 ; i >= 0 ; i--){
+
+ this.removeMatchIfBad( i );
+
+ }
+
+ };
+
+
+ MatchCollection.prototype.removeMatchIfBad = function( index ){
+
+ if (!this._values[ index ].isPromising()){
+
+ this._values.splice( index, 1 );
+
+ }
+
+ };
+
+
+
+ // -------------------------------------------------- //
+ // -------------------------------------------------- //
+
+
+ // Return constructor definition.
+ return( MatchCollection );
+
+
+ }
+);
@@ -1,20 +0,0 @@
-
-// Define class requirments and cosntructor.
-define(
- [],
- function(){
-
- function Collection(){
-
- }
-
-
- // -------------------------------------------------- //
- // -------------------------------------------------- //
-
-
- // Return constructor definition.
- return( Collection );
-
- }
-);
@@ -0,0 +1,29 @@
+
+// Define class requirments and cosntructor.
+define(
+ [
+ "../util/Collection"
+ ],
+ function( Collection ){
+
+
+ function PersonCollection(){
+
+ Collection.apply( this, arguments )
+
+ }
+
+
+ PersonCollection.prototype = Object.create( Collection.prototype );
+
+
+ // -------------------------------------------------- //
+ // -------------------------------------------------- //
+
+
+ // Return constructor definition.
+ return( PersonCollection );
+
+
+ }
+);
@@ -18,7 +18,7 @@ define(
FemalePreference.prototype = Object.create( Preference );
- FemalePreference.prototype.isSexuallyAppealing = function( person ){
+ FemalePreference.prototype.prefers = function( person ){
return( person.isFemale() );
@@ -18,7 +18,7 @@ define(
MalePreference.prototype = Object.create( Preference );
- MalePreference.prototype.isSexuallyAppealing = function( person ){
+ MalePreference.prototype.prefers = function( person ){
return( person.isMale() );
@@ -18,7 +18,7 @@ define(
NonPreference.prototype = Object.create( Preference );
- NonPreference.prototype.isSexuallyAppealing = function( person ){
+ NonPreference.prototype.prefers = function( person ){
// Gender is irrelevant.
return( true );
@@ -17,7 +17,7 @@ define(
isAttractedTo: function( person ){
return(
- this._preference.isSexuallyAppealing( person )
+ this._preference.prefers( person )
);
},
@@ -10,7 +10,7 @@ define(
}
- Preference.prototype.isSexuallyAppealing = function( person ){
+ Preference.prototype.prefers = function( person ){
throw( new Error( "AbstractMethod" ) );
Oops, something went wrong.

0 comments on commit 0e0de36

Please sign in to comment.