Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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);
}
@ValentinDrazdov
Copy link

ValentinDrazdov commented Feb 22, 2019

It's better to use ENUMs than just return integer code of error :-)

@plechev
Copy link

plechev commented Mar 14, 2019

Code written 4 years ago and: (1) still with only one revision, (2) has not been deleted. What better proof of great and lasting design?

@kingcc
Copy link

kingcc commented Jul 9, 2019

Quite rigorous LOL

@PoolloverNathan
Copy link

PoolloverNathan commented Sep 6, 2019

I did an F3 with hello world, and it skipped over the code. What kind of hello world doesn't mention "hello world"?


Editlog:

  1. Backticked the search query.
  2. The horizontal line I added for the editlog made the main content become a h1.
  3. Backticked the F3 key.
  4. Turned all the entries in the editlog to 1.s! 😆
  5. The emoji didn't render right.

@jandrusk
Copy link

jandrusk commented Sep 18, 2019

No regex's? What a failure.

@tail-call
Copy link

tail-call commented Sep 23, 2019

This needs to utilise a DI framework.

@MostHated
Copy link

MostHated commented Sep 27, 2019

Will this keep track of my cats sleep cycles? He keeps having loose stool on Thursday afternoons.

@sadko4u
Copy link

sadko4u commented Oct 1, 2019

The same thing I saw in one book about Spring 4.
After that, I got a strong desire to burn this book in fire.

@andrastothtw
Copy link

andrastothtw commented Jan 13, 2020

I am going to write the requirements docs for an enterprise grade hello world.

You will have:

  • translations to 24 languages (including right-to-left writing systems)
  • cookie consent and GDPR settings
  • a "hello" and a "world" microservice
  • reasonable test coverage for both services and contract tests in between them
  • a task about finding a non-fragile E2E test framework that does not break mystically time-to-time
  • setting up a dev and a staging environment
  • setting CI pipeline for instant deployment and rollbacks
  • setting up remote logging and service performance metrics
  • task to discuss whether React or Angular or Vue and then whether to use Redux if later it gets way more interactive
  • setting up automatized way of dealing with translators
  • add at least 3 different tracking providers for different divisions (google analytics and so on)
  • add twitter, facebook, instagram integrations
  • ...

And maybe then you can write the first line of code for hello world.

@es20490446e
Copy link

es20490446e commented Jan 16, 2020

Next step, the test-case.

@codeMonkey404
Copy link

codeMonkey404 commented Jan 17, 2020

There is micro services? with different rest api's separated by load balancer.

@girng
Copy link

girng commented Apr 4, 2020

LOLLLLL

@tcthien
Copy link

tcthien commented Apr 28, 2020

Best of the best hello world I have seen. I think it should have service registry, load balancer and the hello string should be store in a cluster of mysql database with replica setup 🥇

@Quantium
Copy link

Quantium commented May 8, 2020

After @andrastothtw finish the microservices, this will need a Javascript SDK to implement it in other proyects. I'm pretty sure that several projects that use the Hello World functionality are created everyday.

One the SDK is ready we'll need to translate it to Fortran, C++, Ada, C, Assemby and ActionScript 2.0.
If the community grows I'll found a business that provide SaaS Hello World functionality based on this standars
In order to keep a clean and just implementation of the standar, We should create a council that meets every month to governance and monitoring with periodic publications about it

@goyzhang
Copy link

goyzhang commented Jun 24, 2020

Lol. There is a code smell that IHelloWorldString and IPrintStrategy are extracted from helloworld and then you put them back to print! Clients are doing something they don't have to for you! YOU SHALL REFACTOR those three lines into one! XD

@overtakerx
Copy link

overtakerx commented Jul 20, 2020

need some form of DI using reflection too

@CTimmerman
Copy link

CTimmerman commented Sep 18, 2020

Try increasing the line count to at least 6000, twice for good measure, and another twice in a different framework for quick design proposals. Of course with a giant Wiki documenting the steps to set up the Kubernetes to manage the Docker instances on the cloud servers.

@girng
Copy link

girng commented Sep 19, 2020

@CTimmerman ahaha

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

greatvovan commented Dec 8, 2020

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

@fabiojwalter
Copy link

fabiojwalter commented Apr 9, 2021

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

@h4sohail
Copy link

h4sohail commented Apr 25, 2021

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

zhouyijiaren commented Apr 8, 2022

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!

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