Skip to content

Instantly share code, notes, and snippets.

@jaykz52
jaykz52 / Suit_enum.cs
Created December 14, 2010 00:45
Example Enum value
public Enum Suit
{
Spades,
Clubs,
Diamonds,
Hearts
}
@jaykz52
jaykz52 / Suit_Class.cs
Created December 14, 2010 00:49
An example of implementing the "typesafe enum" pattern in .NET
public class Suit
{
public static readonly Suit CLUBS = new Suit("Hearts");
public static readonly Suit DIAMONDS = new Suit("Diamonds");
public static readonly Suit HEARTS = new Suit("Hearts");
public static readonly Suit SPADES = new Suit("Spades");
private Suit(string pName)
{
name = pName;
@jaykz52
jaykz52 / SomeClass.cs
Created December 14, 2010 02:20
A class demonstrating the stereotypical starting point for most class constructor
public class SomeClass
{
public SomeClass()
{
// do something awesome here
}
}
@jaykz52
jaykz52 / DBConnection.cs
Created December 14, 2010 02:33
An example of place where constructors don't allow us full control over a class's behavior
public class DBConnection
{
private const int MAXCONNECTIONS = 5; // arbitrary
public DBConnection()
{
// Oh no, what if we're over the max allowed connections!
}
}
@jaykz52
jaykz52 / DBConnection_NoCompile.cs
Created December 14, 2010 02:57
An example of a situation where a developer is limited by constructor rules
// this class doesn't compile!
public class DBConnection
{
public DBConnection(string pConnectionString, bool pIsTransactional)
{
// do something mind-blowingly awesome
}
public DBConnection(string pConnectionString, bool pKeepAlive)
{
@jaykz52
jaykz52 / DBConnection_With_Factory.cs
Created December 14, 2010 03:10
An example of using static factory methods in place of constructors
public class DBConnection
{
private const int MAXCONNECTIONS = 5;
private static int connectionsOpen = 0;
private DBConnection(){}
// static factory in some sort of pooling situation
public static DBConnection GetConnection()
{
@jaykz52
jaykz52 / style.css
Created December 15, 2010 03:49
An example of how we traditionally handle the various anchor states
a {
text-decoration: none;
color: green;
}
a:hover {
text-decoration: underline;
}
a:active {
color: purple;
}
@jaykz52
jaykz52 / style.scss
Created December 15, 2010 03:55
An example of nesting/parent references in Sass
a {
color: green;
&:hover {
text-decoration: underline;
}
&:active {
color: purple;
}
&:visited {
color: yellow;
@jaykz52
jaykz52 / theme.scss
Created December 15, 2010 04:26
An example of utilizing variables in Sass files
$main-color: #701A14;
$sub-color: #A64C32;
$accent-color: #BF8B5B;
/* Changing color schemes is as simple as updating the 3 lines above */
p {
color: $main-color;
background-color: $sub-color;
.accent {
color: $sub-color;
@jaykz52
jaykz52 / style_mixins.scss
Created December 16, 2010 00:27
An example of using mixins in Sass
@mixin colorize {
$color: blue;
$bg-color: green;
color: $color;
background-color: $bg-color;
}
p {
@include colorize;
margin-bottom: 20px;