Skip to content

Instantly share code, notes, and snippets.

@slimbo
slimbo / htb-wvh-how.cfc
Last active December 11, 2015 16:58
Hit the Bits! - What vs. How - Demonstrates the importance of writing code that focuses on What instead of How.
public void function sendEmailMessages(string emailTemplate)
{
var msg = "";
var mailer = new Mail();
var totalPointCount = 0;
mailer.setSubject("Thank you for your recent purchase");
mailer.setFrom("[email protected]");
var userQuery = new Query();
userQuery.setDataSource("depot");
userQuery.setSql("select * from EmailList where Category = 5");
@slimbo
slimbo / htb-venusflytrap.cs
Created November 20, 2012 02:47
Hit the Bits! - Venus Fly Trap Polymorphism
Plant rex = new VenusFlyTrap();
@slimbo
slimbo / htb-bugeatercollection-example.cs
Created November 20, 2012 02:40
Hit the Bits! - BugEaterCollection Example in C#
class BugEaterCollection
{
public void addBugEater(BugEater bugEater)
{
// code goes here
}
}
// Calling code can do this:
addBugEater(new VenusFlyTrap());
@slimbo
slimbo / htb-bugeater-example.cs
Created November 20, 2012 02:36
Hit the Bits! - BugEater Example in C#
interface BugEater
{
void consume(Bug bug);
}
class Aardvark : BugEater
{
public void consume(Bug bug)
{
// code goes here
@slimbo
slimbo / htb-oop-interface-iswitch.cs
Created November 8, 2012 02:06
Hit the Bits! - Light Switch Interface
interface ISwitch
{
void turnOn();
void turnOff();
}
@slimbo
slimbo / htb-oop-interface-lightswitch-class.cs
Created November 7, 2012 02:58
Hit the Bits! - Light Switch
class LightSwitch
{
// PUBLIC STUFF PRIVATE STUFF
// ---------------------------- ------------------------------------------------
private Wire inboundWire, outboundWire;
private bool isOn;
public void turnOn()
{
connectWires();
@slimbo
slimbo / htb-oop-interface-lightswitch-poly.cs
Created November 7, 2012 02:50
Hit the Bits! - Light Switch Interface Polymorphic Assignment
ISwitch myLightSwitch = new LightSwitch(wire1, wire2);
@slimbo
slimbo / htb-oop-interface-lightswitch-usage.cs
Created November 7, 2012 02:48
Hit the Bits! - Light Switch Interface Usage
class LightSwitch : ISwitch
{
// Omitting contents for brevity...
}
@slimbo
slimbo / htb-cfinterface.cfc
Created October 31, 2012 03:23
Hit the Bits! - CFInterface - CF Version
<cfscript>
<!--- IAccount.cfc --->
interface
{
public numeric function getBalance();
}
<!--- CheckingAccount.cfc --->
component implements="IAccount"
@slimbo
slimbo / htb-cfinterface.cs
Created October 31, 2012 02:29
Hit the Bits! - CFInterface - C# Version
interface IAccount
{
decimal GetBalance();
}
class CheckingAccount : IAccount
{
public decimal GetBalance()
{
return 0;