Skip to content

Instantly share code, notes, and snippets.

@urfolomeus
Created May 6, 2010 19:01
Show Gist options
  • Save urfolomeus/392557 to your computer and use it in GitHub Desktop.
Save urfolomeus/392557 to your computer and use it in GitHub Desktop.
// inherited - bad
public MyString extends String {
public MyString () {
super();
}
public String capitalize(String string) {
String capString = string.subString(0,1);
capString = first.toUpperCase();
capString += string.subString(1,string.length());
return capString;
}
}
// helper - good
// named well by @srbaker ;)
public StringFondler() {
private final String string;
public StringFondler(String string) {
this.string = string;
}
public String capitalize() {
String capString = this.string.subString(0,1);
capString = first.toUpperCase();
capString += this.string.subString(1,this.string.length());
return capString;
}
}
// calling with inherit
MyString foo = new MyString("hello");
foo.capitalize(); => "Hello"
//calling with helper
String foo = new StringHelper("hello").capitalize; => "Hello"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment