Skip to content

Instantly share code, notes, and snippets.

@lolzballs
Created March 22, 2015 00:21
Show Gist options
  • Save lolzballs/2152bc0f31ee0286b722 to your computer and use it in GitHub Desktop.
Save lolzballs/2152bc0f31ee0286b722 to your computer and use it in GitHub Desktop.
Hello World Enterprise Edition
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
public class HelloWorld{
private static HelloWorld instance;
public static void main(String[] args){
instantiateHelloWorldMainClassAndRun();
}
public static void instantiateHelloWorldMainClassAndRun(){
instance = new HelloWorld();
}
public HelloWorld(){
HelloWorldFactory factory = HelloWorldFactory.getInstance();
IHelloWorld helloWorld = factory.createHelloWorld();
IHelloWorldString helloWorldString = helloWorld.getHelloWorld();
IPrintStrategy printStrategy = helloWorld.getPrintStrategy();
IStatusCode code = helloWorld.print(printStrategy, helloWorldString);
if(code.getStatusCode() != 0){
throw new RuntimeException("Failed to print: " + code.getStatusCode());
}
}
}
class StringFactory{
private static StringFactory instance = new StringFactory();
public static StringFactory getInstance(){
return instance;
}
public HelloWorldString createHelloWorldString(String str){
HelloWorldString s = new HelloWorldString();
s.s = str;
return s;
}
}
class PrintStrategyFactory{
private static PrintStrategyFactory instance = new PrintStrategyFactory();
public static PrintStrategyFactory getInstance(){
return instance;
}
public IPrintStrategy createIPrintStrategy(){
IPrintStrategy printStrategy = new PrintStrategyImplementation();
IStatusCode code = printStrategy.setupPrinting();
if(code.getStatusCode() != 0){
throw new RuntimeException("Failed to create IPrintStrategy: " + code.getStatusCode());
}
return printStrategy;
}
}
class PrintStrategyImplementation implements IPrintStrategy{
private OutputStream print;
public IStatusCode setupPrinting() {
try{
FileDescriptor descriptor = FileDescriptor.out;
print = new FileOutputStream(descriptor);
return new StatusCodeImplementation(0);
}
catch(Exception e){
return new StatusCodeImplementation(-1);
}
}
public IStatusCode print(IHelloWorldString string) {
try{
print.write(string.getHelloWorldString().getHelloWorldString().concat("\n").getBytes("UTF-8"));
return new StatusCodeImplementation(0);
}
catch(Exception e){
return new StatusCodeImplementation(-1);
}
}
}
class StatusCodeImplementation implements IStatusCode{
private int code;
public StatusCodeImplementation(int code){
this.code = code;
}
public int getStatusCode() {
return code;
}
}
class HelloWorldString{
String s;
public String getHelloWorldString(){
return s;
}
}
class HelloWorldStringImplementation implements IHelloWorldString{
public HelloWorldString getHelloWorldString(){
StringFactory factory = StringFactory.getInstance();
HelloWorldString s = factory.createHelloWorldString("Hello, World!");
return s;
}
}
class HelloWorldFactory{
private static HelloWorldFactory instance = new HelloWorldFactory();
public static HelloWorldFactory getInstance(){
return instance;
}
public IHelloWorld createHelloWorld(){
IHelloWorld helloWorld = new HelloWorldImplementation();
return helloWorld;
}
}
class HelloWorldImplementation implements IHelloWorld{
public IHelloWorldString getHelloWorld() {
IHelloWorldString string = new HelloWorldStringImplementation();
return string;
}
public IPrintStrategy getPrintStrategy() {
PrintStrategyFactory factory = PrintStrategyFactory.getInstance();
return factory.createIPrintStrategy();
}
public IStatusCode print(IPrintStrategy strategy, IHelloWorldString toPrint) {
IStatusCode code = strategy.print(toPrint);
return code;
}
}
interface IHelloWorldString{
public HelloWorldString getHelloWorldString();
}
interface IHelloWorld{
public IHelloWorldString getHelloWorld();
public IPrintStrategy getPrintStrategy();
public IStatusCode print(IPrintStrategy strategy, IHelloWorldString toPrint);
}
interface IStatusCode{
public int getStatusCode();
}
interface IPrintStrategy{
public IStatusCode setupPrinting();
public IStatusCode print(IHelloWorldString string);
}
@tristanvandam
Copy link

Unfortunately this is not event driven. Please refactor. 😉

@Rakhsan
Copy link

Rakhsan commented Feb 5, 2025

Needs documentation

in 2025 still no docs

@Rakhsan
Copy link

Rakhsan commented Feb 5, 2025

code needs comments

@PaulStSmith
Copy link

Needs documentation

in 2025 still no docs

Well... I added comments to the code: https://gist.github.com/PaulStSmith/640f83a3fbcaa55de180b4eee10ee2f5

@ChrisHodges
Copy link

ChrisHodges commented Mar 10, 2025

Needs documentation

in 2025 still no docs

Well... I added comments to the code: https://gist.github.com/PaulStSmith/640f83a3fbcaa55de180b4eee10ee2f5

Honestly it's great that you've done that but without a way for our consumers to consume your comments it's probably not that useful. As an experienced PM (I don't want to pull rank but I am pretty 'bedded in' round here, thanks, lol, thanks) can I suggest:

  • Create a CD pipeline for this project (which really should have been done already. It's 2025!)
  • Get signoff from devops
  • Add a build step that generates a static website from the comments, ensuring that the static website confirms with our 209 point in-house style guide
  • Get signoff from branding
  • Implement semver for this project (It's 2025!)
  • Serve to a sensible subdomain which confirms to our internal ops subdomain naming policy e.g. user-friendly-documentation.v.1.0.0.hello.world.enterpriseedition.com
  • Get signoff from whoever administers our DNS (I don't know who that is but I'm sure you can find it on the org directory)
  • Get signoff from me
  • By close of play
  • Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment