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);
}
Copy link

ghost commented Oct 27, 2020

Sufficiently advanced Java is indistinguishable from satire.

@KulaGGin
Copy link

KulaGGin commented Nov 6, 2020

Everything is in the same file? Ew! Here's a proper Enterprise edition: https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition

@greatvovan
Copy link

Code is not structured!

@marcoffee
Copy link

marcoffee commented Mar 4, 2021

One of the customers is complaining that the letter o in Hello World is too similar to the digit 0 and it is giving him a headache. You have until tomorrow morning to solve it.

@codeMonkey404
Copy link

codeMonkey404 commented Mar 4, 2021 via email

@fabiojwalter
Copy link

It needs some externalized configurations and definitely a IoC/DI engine.

@h4sohail
Copy link

Where is the CI/CD pipeline?

@billdion
Copy link

billdion commented Jun 7, 2021

yes

@CTimmerman
Copy link

CTimmerman commented Jun 10, 2021

Line 71, among others, exceeds 80 characters. This is terrible for legacy reasons. CPU cycles to wrap lines aren't free, and neither is training to enable that.

@ChrisHodges
Copy link

ChrisHodges commented Mar 22, 2022

Sheesh. If you're happy with code that doesn't abstract StringFactory into an interface then please feel free to send this to production as is. But my product manager is gonna go insane if we want to swap it out for another kind of string factory for reasons. I heard that GoodbyeWorld() is in the offing for quarter 3 and we're going to want to reuse as much of the existing codebase as possible so maybe you might want to think about that?

@zhouyijiaren
Copy link

no scalability

@m256i
Copy link

m256i commented Apr 24, 2022

why are there no comments?? why is the formatting so weird? also this is obviously performance critical code that should be written in assembly! also how do you expect a 200 line program to run and ship on hundreds of platforms? literally unusable!

@partap
Copy link

partap commented Jul 26, 2022

No i18n support???

@ricardozv
Copy link

hahaha sorry

@diivanand
Copy link

Lol in terms of “enterprise good practice” for local variables in functions/methods that are not meant to be reassigned you should be using the “final” keyword. Same for function/method Paramus that are not meant to be reassigned, use the “final” keyword.

Otherwise the checkstyle PRB might get made at you :p

Also does this repo have required checkstyle PRB, spotbugs PRB, and unit test with jacoco code coversge enforcement PRB required to pass to allow merges along with at least one approval by someone else? If not tsk tsk…

(btw I know this is a funny joke repo on enterprise app over-engineering but I’m just playing along).

@landwill
Copy link

landwill commented Feb 7, 2024

lgtm

@bitsnaps
Copy link

bitsnaps commented Feb 7, 2024

Now, what if the format of the output is not structured? do we need an LLM and StructuredOutputParser? then make sure to deploy it on the Edge!

@tristanvandam
Copy link

Unfortunately this is not event driven. Please refactor. 😉

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