Skip to content

Commit c5cdd5e

Browse files
author
Badacadabra
committed
Refactor everything using modules
1 parent e64ea37 commit c5cdd5e

File tree

585 files changed

+8608
-7149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

585 files changed

+8608
-7149
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tags
Binary file not shown.
Loading
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict'
2+
3+
# ==============================
4+
# ABSTRACT RACER
5+
# ==============================
6+
7+
class Racer
8+
constructor: ->
9+
throw new Error "You cannot instantiate an abstract class!" if @constructor is Racer
10+
11+
go: ->
12+
res = ""
13+
if @nextRelay? then res += @nextRelay.go() else res += ""
14+
res
15+
16+
setNextRelay: (relay) ->
17+
@nextRelay = relay
18+
19+
module.exports = Racer
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict'
2+
3+
Racer = require './Racer'
4+
5+
# ==============================
6+
# CONCRETE RACER
7+
# ==============================
8+
9+
class Runner extends Racer
10+
go: ->
11+
"Runner: go!\n#{super}"
12+
13+
module.exports = Runner
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict'
2+
3+
Racer = require './Racer'
4+
5+
# ==============================
6+
# CONCRETE RACER
7+
# ==============================
8+
9+
class Swimmer extends Racer
10+
go: ->
11+
"Swimmer: go!\n#{super}"
12+
13+
module.exports = Swimmer
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict'
2+
3+
Racer = require './Racer'
4+
5+
# ==============================
6+
# CONCRETE RACER
7+
# ==============================
8+
9+
class Walker extends Racer
10+
go: ->
11+
"Walker: go!\n#{super}"
12+
13+
module.exports = Walker

src/CoffeeScript/GoF/Behavioral/ChainOfResponsibility/ChainOfResponsibility.coffee

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict'
2+
3+
Walker = require './API/Walker'
4+
Runner = require './API/Runner'
5+
Swimmer = require './API/Swimmer'
6+
7+
# ==============================
8+
# CLIENT CODE
9+
# ==============================
10+
11+
walker = new Walker
12+
runner = new Runner
13+
swimmer = new Swimmer
14+
15+
walker.setNextRelay runner
16+
runner.setNextRelay swimmer
17+
18+
console.log walker.go()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict'
2+
3+
# ==============================
4+
# CONCRETE CUSTOMER
5+
# ==============================
6+
7+
class Customer
8+
pay: ->
9+
"Payment OK!\n"
10+
11+
module.exports = Customer
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict'
2+
3+
# ==============================
4+
# ABSTRACT ORDER
5+
# ==============================
6+
7+
class Order
8+
constructor: ->
9+
throw new Error "You cannot instantiate an abstract class!" if @constructor is Order
10+
11+
deliver: ->
12+
throw new Error "You cannot call an abstract method!"
13+
14+
module.exports = Order
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict'
2+
3+
# ==============================
4+
# CONCRETE RESTAURANT
5+
# ==============================
6+
7+
class Restaurant
8+
constructor: ->
9+
@_orders = []
10+
11+
addOrder: (order) ->
12+
@_orders.push order
13+
14+
prepareOrders: ->
15+
summary = ""
16+
summary += order.deliver() for order in @_orders
17+
summary
18+
19+
module.exports = Restaurant
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict'
2+
3+
Order = require './Order'
4+
5+
# ==============================
6+
# CONCRETE ORDER
7+
# ==============================
8+
9+
class TexMex extends Order
10+
constructor: (@customer) ->
11+
12+
deliver: ->
13+
@customer.pay()
14+
15+
module.exports = TexMex

src/CoffeeScript/GoF/Behavioral/Command/Command.coffee

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict'
2+
3+
Customer = require './API/Customer'
4+
TexMex = require './API/TexMex'
5+
Restaurant = require './API/Restaurant'
6+
7+
# ==============================
8+
# CLIENT CODE
9+
# ==============================
10+
11+
customer = new Customer
12+
order = new TexMex customer
13+
restaurant = new Restaurant
14+
15+
restaurant.addOrder order
16+
console.log restaurant.prepareOrders()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict'
2+
3+
MusicNotation = require './MusicNotation'
4+
5+
# ==============================
6+
# CONCRETE (NONTERMINAL) EXPRESSION
7+
# ==============================
8+
9+
class Arpeggio extends MusicNotation
10+
constructor: (name) ->
11+
super name
12+
@_notes = []
13+
14+
addNotes: (newNotes) ->
15+
@_notes.push note for note in newNotes
16+
17+
18+
interpret: (sonata) ->
19+
res = ""
20+
res += note.interpret sonata for note in @_notes
21+
res += "This was a #{@_name} arpeggio from #{sonata.name}.\n"
22+
res
23+
24+
module.exports = Arpeggio
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict'
2+
3+
# ==============================
4+
# ABSTRACT EXPRESSION
5+
# ==============================
6+
7+
class MusicNotation
8+
constructor: (name) ->
9+
throw new Error "You cannot instantiate an abstract class!" if @constructor is MusicNotation
10+
@_name = name
11+
12+
interpret: (sonata) ->
13+
throw new Error "You cannot call an abstract method!"
14+
15+
module.exports = MusicNotation
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict'
2+
3+
MusicNotation = require './MusicNotation'
4+
5+
# ==============================
6+
# CONCRETE (TERMINAL) EXPRESSION
7+
# ==============================
8+
9+
class Note extends MusicNotation
10+
constructor: (name) ->
11+
super name
12+
13+
interpret: (sonata) ->
14+
"#{sonata.composer} played #{@_name}\n"
15+
16+
module.exports = Note
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict'
2+
3+
# ==============================
4+
# CONCRETE CONTEXT
5+
# ==============================
6+
7+
class Sonata
8+
constructor: (@name, @composer) ->
9+
10+
getName: ->
11+
@_name
12+
13+
getComposer: ->
14+
@_composer
15+
16+
module.exports = Sonata

0 commit comments

Comments
 (0)