Created
May 6, 2010 19:01
-
-
Save urfolomeus/392557 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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