Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Hello world using all 23 kinds of GoF design patterns.

License

NotificationsYou must be signed in to change notification settings

code4craft/hello-design-pattern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Hello world using all 23 kinds of GoF design patterns.

publicclassMain {publicstaticvoidmain(String[]args)throwsInstantiationException,IllegalAccessException {//hello=interjection//world=objectSystem.out.println("We are creational patterns!");System.out.println("1. Abstract Factory: ");SplitHelloWorldFactoryabstractFactory =AbstractFactory.select(AbstractFactory.Type.DesignPattern);HelloWorldabstractFactoryHelloWorld =newSplitHelloWorld(abstractFactory.createHelloWorldInterjection(),abstractFactory.createHelloWorldObject());System.out.println(abstractFactoryHelloWorld.helloWorld());System.out.println("2. Builder: ");HelloWorldbuilderHelloWorld =HelloWorldBuilder.builder()                .interjection("Hello")                .object("Builder").getHelloWorld();System.out.println(builderHelloWorld.helloWorld());System.out.println("3. Factory Method: ");/**         * Difference between "abstract factory" and "factory method" is the abstracting point:         *  1. Abstracting point of abstract factory is factory.         *  2. Abstracting point of factory method is generated object.         */FactoryMethodHelloWorldFactoryfactoryMethodHelloWorldFactory =newFactoryMethodHelloWorldFactory();HelloWorldfactoryMethodHelloWorld =factoryMethodHelloWorldFactory.createHelloWorld();System.out.println(factoryMethodHelloWorld.helloWorld());System.out.println("4. Prototype: ");HelloWorldprototypeHelloWorld =HelloWorldPrototype.PROTOTYPE.clone();System.out.println(prototypeHelloWorld.helloWorld());System.out.println("5. Singleton: ");HelloWorldsingletonHelloWorld =HelloWorldSingleton.instance();System.out.println(singletonHelloWorld.helloWorld());System.out.println("====================================");System.out.println("We are structural patterns!");System.out.println("6. Adapter: ");HelloWorldadapterHelloWorld =newHelloWorldAdapter(newHelloAdapterDesignPattern());System.out.println(adapterHelloWorld.helloWorld());System.out.println("7. Bridge: ");HelloWorldbridgeHelloWorld =newHelloWorldBridge(newDesignPatternWorldImpl());//leave bridgeHelloWorld' output to compositeHelloWorldSystem.out.println("8. Composite: ");HelloWorldcompositeHelloWorld =newCompositeHelloWorld(bridgeHelloWorld,newCompositeHelloWorld.DefaultHelloWorld());System.out.println(compositeHelloWorld.helloWorld());System.out.println("9. Decorator: ");HelloWorldDecoratordecoratorHelloWorld =newHelloWorldDecorator(newHelloWorldDecorator.DefaultHelloWorld());System.out.println(decoratorHelloWorld.helloDecorator());System.out.println("10. Facade: ");HelloWorldfacadeHelloWorld =HelloWorldFacade.instance().facadeHelloWorld();System.out.println(facadeHelloWorld.helloWorld());System.out.println("11. Flyweight: ");HelloWorldflyWeightHelloWorld =HelloWorldFlyWeightFactory.instance().createHelloWorld("Hello Flyweight!");System.out.println(flyWeightHelloWorld.helloWorld());System.out.println("12. Proxy: ");HelloWorldproxyHelloWorld =newHelloWorldProxy(newHelloWorldProxy.DefaultHelloWorld());System.out.println(proxyHelloWorld.helloWorld());System.out.println("====================================");System.out.println("We are behavioral patterns!");System.out.println("13. Chain of Responsibility: ");HelloWorldHandlerhelloWorldChainOfResponsibility =newHelloWorldInterjectionHandler().setNext(newHelloWorldObjectHandler());System.out.println(helloWorldChainOfResponsibility.helloWorld());System.out.println("14. Command: ");CommandhelloWorldCommand =newHelloWorldPrintCommand();helloWorldCommand.execute();System.out.println("15. Interpreter: ");HelloWorldInterpreterhelloWorldInterpreter =newHelloWorldInterpreter();helloWorldInterpreter.interpret("println('Hello Interpreter!')");System.out.println("16. Iterator: ");HelloWorldCharacterIteratorhelloWorldCharacterIterator =newHelloWorldCharacterIterator("Hello Iterator!".toCharArray());while (helloWorldCharacterIterator.hasNext()) {System.out.print(helloWorldCharacterIterator.next());        }System.out.println();System.out.println("17. Mediator: ");HelloWorldInterjectionhelloWorldInterjection =newHelloWorldInterjection();HelloWorldObjecthelloWorldObject =newHelloWorldObject();HelloWorldMediatorhelloWorldMediator =newHelloWorldMediator(helloWorldInterjection,helloWorldObject);helloWorldInterjection.setHelloWorldMediator(helloWorldMediator);helloWorldObject.setHelloWorldMediator(helloWorldMediator);System.out.println(helloWorldObject.helloWorld());System.out.println("18. Memento: ");HelloWorldMementoOriginatorhelloWorldMementoOriginator =newHelloWorldMementoOriginator();HelloWorldMementoOriginator.Mementomemento =helloWorldMementoOriginator.set("Hello Memento!").saveToMemento();helloWorldMementoOriginator.set("Hello Whatever!");helloWorldMementoOriginator.restoreFromMemento(memento);System.out.println(helloWorldMementoOriginator.helloWorld());System.out.println("19. Observer: ");Subjectsubject =newSubject().attach(newHelloWorldObserver());subject.notifyObservers();System.out.println("20. State: ");HelloWorldStateContexthelloWorldStateContext =newHelloWorldStateContext();HelloWorldstateHelloWorld =helloWorldStateContext.appendWord("Hello").appendWord("State");System.out.println(stateHelloWorld.helloWorld());System.out.println("21. Strategy: ");HelloWorldStrategyContexthelloWorldStrategyContext =newHelloWorldStrategyContext(newDesignPatternHelloWorldStrategy());System.out.println(helloWorldStrategyContext.helloWorld());System.out.println("22. Template Method: ");HelloWorldtemplateMethodHelloWorld =newTemplateMethodHelloWorld();System.out.println(templateMethodHelloWorld.helloWorld());System.out.println("23. Visitor: ");HelloWorldCharacterElementshelloWorldCharacterElements =newHelloWorldCharacterElements("Hello Visitor!".toCharArray());HelloWorldCharacterVisitorhelloWorldCharacterVisitor =newHelloWorldCharacterVisitor();helloWorldCharacterElements.accept(helloWorldCharacterVisitor);System.out.println(helloWorldCharacterVisitor.helloWorld());    }}

About

Hello world using all 23 kinds of GoF design patterns.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp