Skip to content

Instantly share code, notes, and snippets.

View mikeholmesuk's full-sized avatar

Mike Holmes mikeholmesuk

View GitHub Profile

Keybase proof

I hereby claim:

  • I am mikeholmesuk on github.
  • I am mikeholmesuk (https://keybase.io/mikeholmesuk) on keybase.
  • I have a public key ASB3daedPI3E5EZGsjLoE6NTm9i67ociIILiIHrISEqWvgo

To claim this, I am signing this object:

.theme li {
list-style: none;
}
.theme li:before {
content: '\2022';
display: block;
position:relative;
max-width: 0;
max-height: 0;
left: -10px;
package my.classes.foo;
/**
* Created by mikeholmes on 17/06/15.
*/
public class MyClassImpl implements IManager {
public String firstname;
public String lastname;
protected int age;
private int f;
@mikeholmesuk
mikeholmesuk / Better Singleton
Created October 15, 2014 13:37
An improved implementation of a singleton. This is based on Joshua Bloch's approach to the Singleton pattern and based on an enum.
// Singleton class
public enum Singleton {
INSTANCE;
// Do stuff
}
public class Main {
public static void main (String[] args) {
Singleton singelton = Singleton.INSTANCE;
@mikeholmesuk
mikeholmesuk / Simple Singleton
Created October 15, 2014 13:23
A simple example of the Singleton Pattern using Java. Use of synchronized keyword is so that the Singleton supports multi-threaded operations (as per Head First design patterns)
// Singleton class
public class Singleton {
private Singleton instance;
// Private constructor so cannot be instantiated directly
private Singleton() {}
public static synchronized Singleton getInstance() {
if (instance == null) {
instance = new Singleton();
@mikeholmesuk
mikeholmesuk / Factory Method Pattern
Created October 15, 2014 13:08
This is a somewhat conceited but relevant example of the Factory Method Pattern. This is a more convoluted version of a simple factory pattern (in fact I would implement this as a factory pattern passing the gender in as a parameter to the factory).
// Interface for returned type
public interface Person {
public Gender getGender();
public String getName();
}
// COncrete classes
public class Male implements Person {
// Properties
private String name;
// Entity
public class Person {
// Properties
private String firstname;
private String Lastname;
private Gender gender;
// Assume constructor set rather than getters/ setters
public Person(String firstname, String lastname, Gender gender) {
this.firstname = firstname;
@mikeholmesuk
mikeholmesuk / Abstract Factory Pattern 2
Last active August 29, 2015 14:07
An implementation of the Abstract Factory Pattern written in Java and based on the example given in Wikipedia (http://en.wikipedia.org/wiki/Abstract_factory_pattern)
// Abstract Products
public interface Letter {
public String getIntro();
public String getBody();
}
public interface Resume {
public String getIntro();
public String getBody();
}