├── Abstract Factory ├── .idea │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── Abstract Factory.iml ├── out │ └── production │ │ └── Abstract Factory │ │ ├── AbstractFactory.class │ │ ├── App.class │ │ ├── Blue.class │ │ ├── Circle.class │ │ ├── Color.class │ │ ├── ColorFactory.class │ │ ├── FactoryProducer.class │ │ ├── Green.class │ │ ├── Rectangle.class │ │ ├── Red.class │ │ ├── Shape.class │ │ ├── ShapeFactory.class │ │ └── Square.class └── src │ ├── AbstractFactory.java │ ├── App.java │ ├── Blue.java │ ├── Circle.java │ ├── Color.java │ ├── ColorFactory.java │ ├── FactoryProducer.java │ ├── Green.java │ ├── Rectangle.java │ ├── Red.java │ ├── Shape.java │ ├── ShapeFactory.java │ └── Square.java ├── Adapter Pattern ├── .idea │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── Adapter Pattern.iml ├── out │ └── production │ │ └── Adapter Pattern │ │ ├── AdapterPatternDemo.class │ │ ├── AdvancedMediaPlayer.class │ │ ├── AudioPlayer.class │ │ ├── MediaAdapter.class │ │ ├── MediaPlayer.class │ │ ├── Mp4Player.class │ │ └── VlcPlayer.class └── src │ ├── AdapterPatternDemo.java │ ├── AdvancedMediaPlayer.java │ ├── AudioPlayer.java │ ├── MediaAdapter.java │ ├── MediaPlayer.java │ ├── Mp4Player.java │ └── VlcPlayer.java ├── Bridge Pattern ├── .idea │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── Bridge Pattern.iml ├── out │ └── production │ │ └── Bridge Pattern │ │ ├── BridgePatternDemo.class │ │ ├── Circle.class │ │ ├── DrawAPI.class │ │ ├── GreenCircle.class │ │ ├── RedCircle.class │ │ └── Shape.class └── src │ ├── BridgePatternDemo.java │ ├── Circle.java │ ├── DrawAPI.java │ ├── GreenCircle.java │ ├── RedCircle.java │ └── Shape.java ├── Builder ├── .idea │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── Builder.iml ├── out │ └── production │ │ └── Builder │ │ ├── App.class │ │ ├── Bottle.class │ │ ├── Burger.class │ │ ├── ChickenBurger.class │ │ ├── Coke.class │ │ ├── ColdDrink.class │ │ ├── Item.class │ │ ├── Meal.class │ │ ├── MealBuilder.class │ │ ├── Packing.class │ │ ├── Pepsi.class │ │ ├── VegBurger.class │ │ └── Wrapper.class └── src │ ├── App.java │ ├── Bottle.java │ ├── Burger.java │ ├── ChickenBurger.java │ ├── Coke.java │ ├── ColdDrink.java │ ├── Item.java │ ├── Meal.java │ ├── MealBuilder.java │ ├── Packing.java │ ├── Pepsi.java │ ├── VegBurger.java │ └── Wrapper.java ├── Chain of Responsibility Pattern ├── .idea │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── Chain of Responsibility Pattern.iml ├── out │ └── production │ │ └── Chain of Responsibility Pattern │ │ ├── AbstractLogger.class │ │ ├── ChainPatternDemo.class │ │ ├── ConsoleLogger.class │ │ ├── ErrorLogger.class │ │ └── FileLogger.class └── src │ ├── AbstractLogger.java │ ├── ChainPatternDemo.java │ ├── ConsoleLogger.java │ ├── ErrorLogger.java │ └── FileLogger.java ├── Command Pattern ├── .idea │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── Command Pattern.iml ├── out │ └── production │ │ └── Command Pattern │ │ ├── Broker.class │ │ ├── BuyStock.class │ │ ├── CommandPatternDemo.class │ │ ├── Order.class │ │ ├── SellStock.class │ │ └── Stock.class └── src │ ├── Broker.java │ ├── BuyStock.java │ ├── CommandPatternDemo.java │ ├── Order.java │ ├── SellStock.java │ └── Stock.java ├── Composite Pattern ├── .idea │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── Composite Pattern.iml ├── out │ └── production │ │ └── Composite Pattern │ │ ├── CompositePatternDemo.class │ │ └── Employee.class └── src │ ├── CompositePatternDemo.java │ └── Employee.java ├── Decorator Pattern ├── .idea │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── Decorator Pattern.iml ├── out │ └── production │ │ └── Decorator Pattern │ │ ├── Circle.class │ │ ├── DecoratorPatternDemo.class │ │ ├── Rectangle.class │ │ ├── RedShapeDecorator.class │ │ ├── Shape.class │ │ └── ShapeDecorator.class └── src │ ├── Circle.java │ ├── DecoratorPatternDemo.java │ ├── Rectangle.java │ ├── RedShapeDecorator.java │ ├── Shape.java │ └── ShapeDecorator.java ├── Facade Pattern ├── .idea │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── Facade Pattern.iml ├── out │ └── production │ │ └── Facade Pattern │ │ ├── Circle.class │ │ ├── FacadePatternDemo.class │ │ ├── Rectangle.class │ │ ├── Shape.class │ │ ├── ShapeMaker.class │ │ └── Square.class └── src │ ├── Circle.java │ ├── FacadePatternDemo.java │ ├── Rectangle.java │ ├── Shape.java │ ├── ShapeMaker.java │ └── Square.java ├── Factory Pattern ├── .idea │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── Factory Pattern.iml ├── out │ └── production │ │ └── Factory Pattern │ │ ├── App.class │ │ ├── Circle.class │ │ ├── Rectangle.class │ │ ├── Shape.class │ │ ├── ShapeFactory.class │ │ └── Square.class └── src │ ├── App.java │ ├── Circle.java │ ├── Rectangle.java │ ├── Shape.java │ ├── ShapeFactory.java │ └── Square.java ├── Flyweight Pattern ├── .idea │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── Flyweight Pattern.iml ├── out │ └── production │ │ └── Flyweight Pattern │ │ ├── Circle.class │ │ ├── FlyweightPatternDemo.class │ │ ├── Shape.class │ │ └── ShapeFactory.class └── src │ ├── Circle.java │ ├── FlyweightPatternDemo.java │ ├── Shape.java │ └── ShapeFactory.java ├── Interpreter Pattern ├── .idea │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── Interpreter Pattern.iml ├── out │ └── production │ │ └── Interpreter Pattern │ │ ├── AndExpression.class │ │ ├── Expression.class │ │ ├── InterpreterPatternDemo.class │ │ ├── OrExpression.class │ │ └── TerminalExpression.class └── src │ ├── AndExpression.java │ ├── Expression.java │ ├── InterpreterPatternDemo.java │ ├── OrExpression.java │ └── TerminalExpression.java ├── Iterator Pattern ├── .idea │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── Iterator Pattern.iml ├── out │ └── production │ │ └── Iterator Pattern │ │ ├── Container.class │ │ ├── Iterator.class │ │ ├── IteratorPatternDemo.class │ │ ├── NameRepository$1.class │ │ ├── NameRepository$NameIterator.class │ │ └── NameRepository.class └── src │ ├── Container.java │ ├── Iterator.java │ ├── IteratorPatternDemo.java │ └── NameRepository.java ├── LICENSE ├── Mediator Pattern ├── .idea │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── Mediator Pattern.iml ├── out │ └── production │ │ └── Mediator Pattern │ │ ├── ChatRoom.class │ │ ├── MediatorPatternDemo.class │ │ └── User.class └── src │ ├── ChatRoom.java │ ├── MediatorPatternDemo.java │ └── User.java ├── Memento Pattern ├── .idea │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── Memento Pattern.iml ├── out │ └── production │ │ └── Memento Pattern │ │ ├── CareTaker.class │ │ ├── Memento.class │ │ ├── MementoPatternDemo.class │ │ └── Originator.class └── src │ ├── CareTaker.java │ ├── Memento.java │ ├── MementoPatternDemo.java │ └── Originator.java ├── Observer Pattern ├── .idea │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── Observer Pattern.iml ├── out │ └── production │ │ └── Observer Pattern │ │ ├── BinaryObserver.class │ │ ├── HexaObserver.class │ │ ├── Observer.class │ │ ├── ObserverPatternDemo.class │ │ ├── OctalObserver.class │ │ └── Subject.class └── src │ ├── BinaryObserver.java │ ├── HexaObserver.java │ ├── Observer.java │ ├── ObserverPatternDemo.java │ ├── OctalObserver.java │ └── Subject.java ├── Prototype ├── .idea │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── Prototype.iml ├── out │ └── production │ │ └── Prototype │ │ ├── App.class │ │ ├── Circle.class │ │ ├── Rectangle.class │ │ ├── Shape.class │ │ ├── ShapeCache.class │ │ └── Square.class └── src │ ├── App.java │ ├── Circle.java │ ├── Rectangle.java │ ├── Shape.java │ ├── ShapeCache.java │ └── Square.java ├── Proxy Pattern ├── .idea │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── Proxy Pattern.iml ├── out │ └── production │ │ └── Proxy Pattern │ │ ├── Image.class │ │ ├── ProxyImage.class │ │ ├── ProxyPatternDemo.class │ │ └── RealImage.class └── src │ ├── Image.java │ ├── ProxyImage.java │ ├── ProxyPatternDemo.java │ └── RealImage.java ├── README.md ├── Singleton ├── .idea │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── Singleton.iml ├── out │ └── production │ │ └── Singleton │ │ ├── App.class │ │ └── SingleObject.class └── src │ ├── App.java │ └── SingleObject.java ├── State Pattern ├── .idea │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── State Pattern.iml ├── out │ └── production │ │ └── State Pattern │ │ ├── Context.class │ │ ├── StartState.class │ │ ├── State.class │ │ ├── StatePatternDemo.class │ │ └── StopState.class └── src │ ├── Context.java │ ├── StartState.java │ ├── State.java │ ├── StatePatternDemo.java │ └── StopState.java ├── Strategy Pattern ├── .idea │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── Strategy Pattern.iml ├── out │ └── production │ │ └── Strategy Pattern │ │ ├── Context.class │ │ ├── OperationAdd.class │ │ ├── OperationMultiply.class │ │ ├── OperationSubstract.class │ │ ├── Strategy.class │ │ └── StrategyPatternDemo.class └── src │ ├── Context.java │ ├── OperationAdd.java │ ├── OperationMultiply.java │ ├── OperationSubstract.java │ ├── Strategy.java │ └── StrategyPatternDemo.java ├── Template Pattern ├── .idea │ ├── misc.xml │ ├── modules.xml │ └── workspace.xml ├── Template Pattern.iml ├── out │ └── production │ │ └── Template Pattern │ │ ├── Cricket.class │ │ ├── Football.class │ │ ├── Game.class │ │ └── TemplatePatternDemo.class └── src │ ├── Cricket.java │ ├── Football.java │ ├── Game.java │ └── TemplatePatternDemo.java └── Visitor Pattern ├── .idea ├── misc.xml ├── modules.xml └── workspace.xml ├── Visitor Pattern.iml ├── out └── production │ └── Visitor Pattern │ ├── Computer.class │ ├── ComputerPart.class │ ├── ComputerPartDisplayVisitor.class │ ├── ComputerPartVisitor.class │ ├── Keyboard.class │ ├── Monitor.class │ ├── Mouse.class │ └── VisitorPatternDemo.class └── src ├── Computer.java ├── ComputerPart.java ├── ComputerPartDisplayVisitor.java ├── ComputerPartVisitor.java ├── Keyboard.java ├── Monitor.java ├── Mouse.java └── VisitorPatternDemo.java /Abstract Factory/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Abstract Factory/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Abstract Factory/Abstract Factory.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Abstract Factory/out/production/Abstract Factory/AbstractFactory.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Abstract Factory/out/production/Abstract Factory/AbstractFactory.class -------------------------------------------------------------------------------- /Abstract Factory/out/production/Abstract Factory/App.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Abstract Factory/out/production/Abstract Factory/App.class -------------------------------------------------------------------------------- /Abstract Factory/out/production/Abstract Factory/Blue.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Abstract Factory/out/production/Abstract Factory/Blue.class -------------------------------------------------------------------------------- /Abstract Factory/out/production/Abstract Factory/Circle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Abstract Factory/out/production/Abstract Factory/Circle.class -------------------------------------------------------------------------------- /Abstract Factory/out/production/Abstract Factory/Color.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Abstract Factory/out/production/Abstract Factory/Color.class -------------------------------------------------------------------------------- /Abstract Factory/out/production/Abstract Factory/ColorFactory.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Abstract Factory/out/production/Abstract Factory/ColorFactory.class -------------------------------------------------------------------------------- /Abstract Factory/out/production/Abstract Factory/FactoryProducer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Abstract Factory/out/production/Abstract Factory/FactoryProducer.class -------------------------------------------------------------------------------- /Abstract Factory/out/production/Abstract Factory/Green.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Abstract Factory/out/production/Abstract Factory/Green.class -------------------------------------------------------------------------------- /Abstract Factory/out/production/Abstract Factory/Rectangle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Abstract Factory/out/production/Abstract Factory/Rectangle.class -------------------------------------------------------------------------------- /Abstract Factory/out/production/Abstract Factory/Red.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Abstract Factory/out/production/Abstract Factory/Red.class -------------------------------------------------------------------------------- /Abstract Factory/out/production/Abstract Factory/Shape.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Abstract Factory/out/production/Abstract Factory/Shape.class -------------------------------------------------------------------------------- /Abstract Factory/out/production/Abstract Factory/ShapeFactory.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Abstract Factory/out/production/Abstract Factory/ShapeFactory.class -------------------------------------------------------------------------------- /Abstract Factory/out/production/Abstract Factory/Square.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Abstract Factory/out/production/Abstract Factory/Square.class -------------------------------------------------------------------------------- /Abstract Factory/src/AbstractFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public abstract class AbstractFactory { 5 | abstract Color getColor(String color); 6 | abstract Shape getShape(String shape) ; 7 | } 8 | -------------------------------------------------------------------------------- /Abstract Factory/src/App.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class App { 5 | public static void main(String[] args) { 6 | //get shape factory 7 | AbstractFactory shapeFactory = FactoryProducer.getFactory("SHAPE"); 8 | 9 | //get an object of Shape Circle 10 | Shape shape1 = shapeFactory.getShape("CIRCLE"); 11 | 12 | //call draw method of Shape Circle 13 | shape1.draw(); 14 | 15 | //get an object of Shape Rectangle 16 | Shape shape2 = shapeFactory.getShape("RECTANGLE"); 17 | 18 | //call draw method of Shape Rectangle 19 | shape2.draw(); 20 | 21 | //get an object of Shape Square 22 | Shape shape3 = shapeFactory.getShape("SQUARE"); 23 | 24 | //call draw method of Shape Square 25 | shape3.draw(); 26 | 27 | //get color factory 28 | AbstractFactory colorFactory = FactoryProducer.getFactory("COLOR"); 29 | 30 | //get an object of Color Red 31 | Color color1 = colorFactory.getColor("RED"); 32 | 33 | //call fill method of Red 34 | color1.fill(); 35 | 36 | //get an object of Color Green 37 | Color color2 = colorFactory.getColor("Green"); 38 | 39 | //call fill method of Green 40 | color2.fill(); 41 | 42 | //get an object of Color Blue 43 | Color color3 = colorFactory.getColor("BLUE"); 44 | 45 | //call fill method of Color Blue 46 | color3.fill(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Abstract Factory/src/Blue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class Blue implements Color { 5 | 6 | @Override 7 | public void fill() { 8 | System.out.println("Inside Blue: fill() method."); 9 | } 10 | } -------------------------------------------------------------------------------- /Abstract Factory/src/Circle.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class Circle implements Shape { 5 | @Override 6 | public void draw() { 7 | System.out.println("Inside Circle: draw() method."); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Abstract Factory/src/Color.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public interface Color { 5 | void fill(); 6 | } 7 | -------------------------------------------------------------------------------- /Abstract Factory/src/ColorFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class ColorFactory extends AbstractFactory { 5 | @Override 6 | Color getColor(String color) { 7 | 8 | if(color == null){ 9 | return null; 10 | } 11 | 12 | if(color.equalsIgnoreCase("RED")){ 13 | return new Red(); 14 | 15 | }else if(color.equalsIgnoreCase("GREEN")){ 16 | return new Green(); 17 | 18 | }else if(color.equalsIgnoreCase("BLUE")){ 19 | return new Blue(); 20 | } 21 | 22 | return null; 23 | } 24 | 25 | @Override 26 | Shape getShape(String shape) { 27 | return null; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Abstract Factory/src/FactoryProducer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class FactoryProducer { 5 | public static AbstractFactory getFactory(String choice){ 6 | 7 | if(choice.equalsIgnoreCase("SHAPE")){ 8 | return new ShapeFactory(); 9 | 10 | }else if(choice.equalsIgnoreCase("COLOR")){ 11 | return new ColorFactory(); 12 | } 13 | 14 | return null; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Abstract Factory/src/Green.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class Green implements Color { 5 | 6 | @Override 7 | public void fill() { 8 | System.out.println("Inside Green: fill() method."); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Abstract Factory/src/Rectangle.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class Rectangle implements Shape { 5 | @Override 6 | public void draw() { 7 | System.out.println("Inside Rectangle: draw() method."); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Abstract Factory/src/Red.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class Red implements Color { 5 | 6 | @Override 7 | public void fill() { 8 | System.out.println("Inside Red: fill() method."); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Abstract Factory/src/Shape.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public interface Shape { 5 | void draw(); 6 | } 7 | -------------------------------------------------------------------------------- /Abstract Factory/src/ShapeFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class ShapeFactory extends AbstractFactory { 5 | @Override 6 | Color getColor(String color) { 7 | return null; 8 | } 9 | 10 | @Override 11 | Shape getShape(String shapeType) { 12 | 13 | if(shapeType == null){ 14 | return null; 15 | } 16 | 17 | if(shapeType.equalsIgnoreCase("CIRCLE")){ 18 | return new Circle(); 19 | 20 | }else if(shapeType.equalsIgnoreCase("RECTANGLE")){ 21 | return new Rectangle(); 22 | 23 | }else if(shapeType.equalsIgnoreCase("SQUARE")){ 24 | return new Square(); 25 | } 26 | 27 | return null; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Abstract Factory/src/Square.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class Square implements Shape { 5 | @Override 6 | public void draw() { 7 | System.out.println("Inside Square: draw() method."); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Adapter Pattern/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Adapter Pattern/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Adapter Pattern/Adapter Pattern.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Adapter Pattern/out/production/Adapter Pattern/AdapterPatternDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Adapter Pattern/out/production/Adapter Pattern/AdapterPatternDemo.class -------------------------------------------------------------------------------- /Adapter Pattern/out/production/Adapter Pattern/AdvancedMediaPlayer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Adapter Pattern/out/production/Adapter Pattern/AdvancedMediaPlayer.class -------------------------------------------------------------------------------- /Adapter Pattern/out/production/Adapter Pattern/AudioPlayer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Adapter Pattern/out/production/Adapter Pattern/AudioPlayer.class -------------------------------------------------------------------------------- /Adapter Pattern/out/production/Adapter Pattern/MediaAdapter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Adapter Pattern/out/production/Adapter Pattern/MediaAdapter.class -------------------------------------------------------------------------------- /Adapter Pattern/out/production/Adapter Pattern/MediaPlayer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Adapter Pattern/out/production/Adapter Pattern/MediaPlayer.class -------------------------------------------------------------------------------- /Adapter Pattern/out/production/Adapter Pattern/Mp4Player.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Adapter Pattern/out/production/Adapter Pattern/Mp4Player.class -------------------------------------------------------------------------------- /Adapter Pattern/out/production/Adapter Pattern/VlcPlayer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Adapter Pattern/out/production/Adapter Pattern/VlcPlayer.class -------------------------------------------------------------------------------- /Adapter Pattern/src/AdapterPatternDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class AdapterPatternDemo { 5 | public static void main(String[] args) { 6 | AudioPlayer audioPlayer = new AudioPlayer(); 7 | 8 | audioPlayer.play("mp3", "beyond the horizon.mp3"); 9 | audioPlayer.play("mp4", "alone.mp4"); 10 | audioPlayer.play("vlc", "far far away.vlc"); 11 | audioPlayer.play("avi", "mind me.avi"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Adapter Pattern/src/AdvancedMediaPlayer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class AdvancedMediaPlayer { 5 | 6 | public void playVlc(String fileName) { 7 | 8 | } 9 | 10 | public void playMp4(String fileName) { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Adapter Pattern/src/AudioPlayer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class AudioPlayer extends MediaPlayer { 5 | MediaAdapter mediaAdapter; 6 | 7 | @Override 8 | public void play(String audioType, String fileName) { 9 | 10 | //inbuilt support to play mp3 music files 11 | if(audioType.equalsIgnoreCase("mp3")){ 12 | System.out.println("Playing mp3 file. Name: " + fileName); 13 | } 14 | 15 | //mediaAdapter is providing support to play other file formats 16 | else if(audioType.equalsIgnoreCase("vlc") || audioType.equalsIgnoreCase("mp4")){ 17 | mediaAdapter = new MediaAdapter(audioType); 18 | mediaAdapter.play(audioType, fileName); 19 | } 20 | 21 | else{ 22 | System.out.println("Invalid media. " + audioType + " format not supported"); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Adapter Pattern/src/MediaAdapter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class MediaAdapter extends MediaPlayer { 5 | 6 | AdvancedMediaPlayer advancedMusicPlayer; 7 | 8 | public MediaAdapter(String audioType){ 9 | 10 | if(audioType.equalsIgnoreCase("vlc") ){ 11 | advancedMusicPlayer = new VlcPlayer(); 12 | 13 | }else if (audioType.equalsIgnoreCase("mp4")){ 14 | advancedMusicPlayer = new Mp4Player(); 15 | } 16 | } 17 | 18 | @Override 19 | public void play(String audioType, String fileName) { 20 | 21 | if(audioType.equalsIgnoreCase("vlc")){ 22 | advancedMusicPlayer.playVlc(fileName); 23 | } 24 | else if(audioType.equalsIgnoreCase("mp4")){ 25 | advancedMusicPlayer.playMp4(fileName); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Adapter Pattern/src/MediaPlayer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class MediaPlayer { 5 | public void play(String audioType, String fileName) { 6 | 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Adapter Pattern/src/Mp4Player.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class Mp4Player extends AdvancedMediaPlayer { 5 | 6 | @Override 7 | public void playVlc(String fileName) { 8 | //do nothing 9 | } 10 | 11 | @Override 12 | public void playMp4(String fileName) { 13 | System.out.println("Playing mp4 file. Name: "+ fileName); 14 | } 15 | } -------------------------------------------------------------------------------- /Adapter Pattern/src/VlcPlayer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class VlcPlayer extends AdvancedMediaPlayer { 5 | @Override 6 | public void playVlc(String fileName) { 7 | System.out.println("Playing vlc file. Name: "+ fileName); 8 | } 9 | 10 | @Override 11 | public void playMp4(String fileName) { 12 | //do nothing 13 | } 14 | } -------------------------------------------------------------------------------- /Bridge Pattern/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Bridge Pattern/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Bridge Pattern/Bridge Pattern.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Bridge Pattern/out/production/Bridge Pattern/BridgePatternDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Bridge Pattern/out/production/Bridge Pattern/BridgePatternDemo.class -------------------------------------------------------------------------------- /Bridge Pattern/out/production/Bridge Pattern/Circle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Bridge Pattern/out/production/Bridge Pattern/Circle.class -------------------------------------------------------------------------------- /Bridge Pattern/out/production/Bridge Pattern/DrawAPI.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Bridge Pattern/out/production/Bridge Pattern/DrawAPI.class -------------------------------------------------------------------------------- /Bridge Pattern/out/production/Bridge Pattern/GreenCircle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Bridge Pattern/out/production/Bridge Pattern/GreenCircle.class -------------------------------------------------------------------------------- /Bridge Pattern/out/production/Bridge Pattern/RedCircle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Bridge Pattern/out/production/Bridge Pattern/RedCircle.class -------------------------------------------------------------------------------- /Bridge Pattern/out/production/Bridge Pattern/Shape.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Bridge Pattern/out/production/Bridge Pattern/Shape.class -------------------------------------------------------------------------------- /Bridge Pattern/src/BridgePatternDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class BridgePatternDemo { 5 | public static void main(String[] args) { 6 | Shape redCircle = new Circle(100,100, 10, new RedCircle()); 7 | Shape greenCircle = new Circle(100,100, 10, new GreenCircle()); 8 | 9 | redCircle.draw(); 10 | greenCircle.draw(); 11 | } 12 | } -------------------------------------------------------------------------------- /Bridge Pattern/src/Circle.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class Circle extends Shape { 5 | private int x, y, radius; 6 | 7 | public Circle(int x, int y, int radius, DrawAPI drawAPI) { 8 | super(drawAPI); 9 | this.x = x; 10 | this.y = y; 11 | this.radius = radius; 12 | } 13 | 14 | public void draw() { 15 | drawAPI.drawCircle(radius,x,y); 16 | } 17 | } -------------------------------------------------------------------------------- /Bridge Pattern/src/DrawAPI.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public interface DrawAPI { 5 | public void drawCircle(int radius, int x, int y); 6 | } 7 | -------------------------------------------------------------------------------- /Bridge Pattern/src/GreenCircle.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class GreenCircle implements DrawAPI { 5 | @Override 6 | public void drawCircle(int radius, int x, int y) { 7 | System.out.println("Drawing Circle[ color: green, radius: " + radius + ", x: " + x + ", " + y + "]"); 8 | } 9 | } -------------------------------------------------------------------------------- /Bridge Pattern/src/RedCircle.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class RedCircle implements DrawAPI { 5 | @Override 6 | public void drawCircle(int radius, int x, int y) { 7 | System.out.println("Drawing Circle[ color: red, radius: " + radius + ", x: " + x + ", " + y + "]"); 8 | } 9 | } -------------------------------------------------------------------------------- /Bridge Pattern/src/Shape.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public abstract class Shape { 5 | protected DrawAPI drawAPI; 6 | 7 | protected Shape(DrawAPI drawAPI){ 8 | this.drawAPI = drawAPI; 9 | } 10 | public abstract void draw(); 11 | } -------------------------------------------------------------------------------- /Builder/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Builder/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Builder/Builder.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Builder/out/production/Builder/App.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Builder/out/production/Builder/App.class -------------------------------------------------------------------------------- /Builder/out/production/Builder/Bottle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Builder/out/production/Builder/Bottle.class -------------------------------------------------------------------------------- /Builder/out/production/Builder/Burger.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Builder/out/production/Builder/Burger.class -------------------------------------------------------------------------------- /Builder/out/production/Builder/ChickenBurger.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Builder/out/production/Builder/ChickenBurger.class -------------------------------------------------------------------------------- /Builder/out/production/Builder/Coke.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Builder/out/production/Builder/Coke.class -------------------------------------------------------------------------------- /Builder/out/production/Builder/ColdDrink.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Builder/out/production/Builder/ColdDrink.class -------------------------------------------------------------------------------- /Builder/out/production/Builder/Item.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Builder/out/production/Builder/Item.class -------------------------------------------------------------------------------- /Builder/out/production/Builder/Meal.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Builder/out/production/Builder/Meal.class -------------------------------------------------------------------------------- /Builder/out/production/Builder/MealBuilder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Builder/out/production/Builder/MealBuilder.class -------------------------------------------------------------------------------- /Builder/out/production/Builder/Packing.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Builder/out/production/Builder/Packing.class -------------------------------------------------------------------------------- /Builder/out/production/Builder/Pepsi.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Builder/out/production/Builder/Pepsi.class -------------------------------------------------------------------------------- /Builder/out/production/Builder/VegBurger.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Builder/out/production/Builder/VegBurger.class -------------------------------------------------------------------------------- /Builder/out/production/Builder/Wrapper.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Builder/out/production/Builder/Wrapper.class -------------------------------------------------------------------------------- /Builder/src/App.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class App { 5 | public static void main(String[] args) { 6 | 7 | MealBuilder mealBuilder = new MealBuilder(); 8 | 9 | Meal vegMeal = mealBuilder.prepareVegMeal(); 10 | System.out.println("Veg Meal"); 11 | vegMeal.showItems(); 12 | System.out.println("Total Cost: " + vegMeal.getCost()); 13 | 14 | Meal nonVegMeal = mealBuilder.prepareNonVegMeal(); 15 | System.out.println("\n\nNon-Veg Meal"); 16 | nonVegMeal.showItems(); 17 | System.out.println("Total Cost: " + nonVegMeal.getCost()); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Builder/src/Bottle.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class Bottle extends Packing { 5 | @Override 6 | public String pack() { 7 | return "Bottle"; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Builder/src/Burger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public abstract class Burger implements Item { 5 | 6 | @Override 7 | public Packing packing() { 8 | return new Wrapper(); 9 | } 10 | 11 | @Override 12 | public abstract float price(); 13 | } -------------------------------------------------------------------------------- /Builder/src/ChickenBurger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class ChickenBurger extends Burger { 5 | 6 | @Override 7 | public float price() { 8 | return 50.5f; 9 | } 10 | 11 | @Override 12 | public String name() { 13 | return "Chicken Burger"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Builder/src/Coke.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class Coke extends ColdDrink { 5 | 6 | @Override 7 | public float price() { 8 | return 30.0f; 9 | } 10 | 11 | @Override 12 | public String name() { 13 | return "Coke"; 14 | } 15 | } -------------------------------------------------------------------------------- /Builder/src/ColdDrink.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public abstract class ColdDrink implements Item { 5 | 6 | @Override 7 | public Packing packing() { 8 | return new Bottle(); 9 | } 10 | 11 | @Override 12 | public abstract float price(); 13 | } -------------------------------------------------------------------------------- /Builder/src/Item.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public interface Item { 5 | public String name(); 6 | public Packing packing(); 7 | public float price(); 8 | } 9 | -------------------------------------------------------------------------------- /Builder/src/Meal.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | public class Meal { 8 | private List items = new ArrayList(); 9 | 10 | public void addItem(Item item){ 11 | items.add(item); 12 | } 13 | 14 | public float getCost(){ 15 | float cost = 0.0f; 16 | 17 | for (Item item : items) { 18 | cost += item.price(); 19 | } 20 | return cost; 21 | } 22 | 23 | public void showItems(){ 24 | 25 | for (Item item : items) { 26 | System.out.print("Item : " + item.name()); 27 | System.out.print(", Packing : " + item.packing().pack()); 28 | System.out.println(", Price : " + item.price()); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Builder/src/MealBuilder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class MealBuilder { 5 | public Meal prepareVegMeal (){ 6 | Meal meal = new Meal(); 7 | meal.addItem(new VegBurger()); 8 | meal.addItem(new Coke()); 9 | return meal; 10 | } 11 | 12 | public Meal prepareNonVegMeal (){ 13 | Meal meal = new Meal(); 14 | meal.addItem(new ChickenBurger()); 15 | meal.addItem(new Pepsi()); 16 | return meal; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Builder/src/Packing.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class Packing { 5 | public String pack() { 6 | return null; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Builder/src/Pepsi.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class Pepsi extends ColdDrink { 5 | 6 | @Override 7 | public float price() { 8 | return 35.0f; 9 | } 10 | 11 | @Override 12 | public String name() { 13 | return "Pepsi"; 14 | } 15 | } -------------------------------------------------------------------------------- /Builder/src/VegBurger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class VegBurger extends Burger { 5 | 6 | @Override 7 | public float price() { 8 | return 25.0f; 9 | } 10 | 11 | @Override 12 | public String name() { 13 | return "Veg Burger"; 14 | } 15 | } -------------------------------------------------------------------------------- /Builder/src/Wrapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class Wrapper extends Packing { 5 | 6 | @Override 7 | public String pack() { 8 | return "Wrapper"; 9 | } 10 | } -------------------------------------------------------------------------------- /Chain of Responsibility Pattern/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Chain of Responsibility Pattern/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Chain of Responsibility Pattern/Chain of Responsibility Pattern.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Chain of Responsibility Pattern/out/production/Chain of Responsibility Pattern/AbstractLogger.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Chain of Responsibility Pattern/out/production/Chain of Responsibility Pattern/AbstractLogger.class -------------------------------------------------------------------------------- /Chain of Responsibility Pattern/out/production/Chain of Responsibility Pattern/ChainPatternDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Chain of Responsibility Pattern/out/production/Chain of Responsibility Pattern/ChainPatternDemo.class -------------------------------------------------------------------------------- /Chain of Responsibility Pattern/out/production/Chain of Responsibility Pattern/ConsoleLogger.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Chain of Responsibility Pattern/out/production/Chain of Responsibility Pattern/ConsoleLogger.class -------------------------------------------------------------------------------- /Chain of Responsibility Pattern/out/production/Chain of Responsibility Pattern/ErrorLogger.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Chain of Responsibility Pattern/out/production/Chain of Responsibility Pattern/ErrorLogger.class -------------------------------------------------------------------------------- /Chain of Responsibility Pattern/out/production/Chain of Responsibility Pattern/FileLogger.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Chain of Responsibility Pattern/out/production/Chain of Responsibility Pattern/FileLogger.class -------------------------------------------------------------------------------- /Chain of Responsibility Pattern/src/AbstractLogger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public abstract class AbstractLogger { 5 | public static int INFO = 1; 6 | public static int DEBUG = 2; 7 | public static int ERROR = 3; 8 | 9 | protected int level; 10 | 11 | //next element in chain or responsibility 12 | protected AbstractLogger nextLogger; 13 | 14 | public void setNextLogger(AbstractLogger nextLogger){ 15 | this.nextLogger = nextLogger; 16 | } 17 | 18 | public void logMessage(int level, String message){ 19 | if(this.level <= level){ 20 | write(message); 21 | } 22 | if(nextLogger !=null){ 23 | nextLogger.logMessage(level, message); 24 | } 25 | } 26 | 27 | abstract protected void write(String message); 28 | 29 | } -------------------------------------------------------------------------------- /Chain of Responsibility Pattern/src/ChainPatternDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class ChainPatternDemo { 5 | 6 | private static AbstractLogger getChainOfLoggers(){ 7 | 8 | AbstractLogger errorLogger = new ErrorLogger(AbstractLogger.ERROR); 9 | AbstractLogger fileLogger = new FileLogger(AbstractLogger.DEBUG); 10 | AbstractLogger consoleLogger = new ConsoleLogger(AbstractLogger.INFO); 11 | 12 | errorLogger.setNextLogger(fileLogger); 13 | fileLogger.setNextLogger(consoleLogger); 14 | 15 | return errorLogger; 16 | } 17 | 18 | public static void main(String[] args) { 19 | AbstractLogger loggerChain = getChainOfLoggers(); 20 | 21 | loggerChain.logMessage(AbstractLogger.INFO, 22 | "This is an information."); 23 | 24 | loggerChain.logMessage(AbstractLogger.DEBUG, 25 | "This is an debug level information."); 26 | 27 | loggerChain.logMessage(AbstractLogger.ERROR, 28 | "This is an error information."); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Chain of Responsibility Pattern/src/ConsoleLogger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class ConsoleLogger extends AbstractLogger { 5 | 6 | public ConsoleLogger(int level){ 7 | this.level = level; 8 | } 9 | 10 | @Override 11 | protected void write(String message) { 12 | System.out.println("Standard Console::Logger: " + message); 13 | } 14 | } -------------------------------------------------------------------------------- /Chain of Responsibility Pattern/src/ErrorLogger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class ErrorLogger extends AbstractLogger { 5 | 6 | public ErrorLogger(int level){ 7 | this.level = level; 8 | } 9 | 10 | @Override 11 | protected void write(String message) { 12 | System.out.println("Error Console::Logger: " + message); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chain of Responsibility Pattern/src/FileLogger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class FileLogger extends AbstractLogger { 5 | 6 | public FileLogger(int level){ 7 | this.level = level; 8 | } 9 | 10 | @Override 11 | protected void write(String message) { 12 | System.out.println("File::Logger: " + message); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Command Pattern/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Command Pattern/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Command Pattern/Command Pattern.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Command Pattern/out/production/Command Pattern/Broker.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Command Pattern/out/production/Command Pattern/Broker.class -------------------------------------------------------------------------------- /Command Pattern/out/production/Command Pattern/BuyStock.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Command Pattern/out/production/Command Pattern/BuyStock.class -------------------------------------------------------------------------------- /Command Pattern/out/production/Command Pattern/CommandPatternDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Command Pattern/out/production/Command Pattern/CommandPatternDemo.class -------------------------------------------------------------------------------- /Command Pattern/out/production/Command Pattern/Order.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Command Pattern/out/production/Command Pattern/Order.class -------------------------------------------------------------------------------- /Command Pattern/out/production/Command Pattern/SellStock.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Command Pattern/out/production/Command Pattern/SellStock.class -------------------------------------------------------------------------------- /Command Pattern/out/production/Command Pattern/Stock.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Command Pattern/out/production/Command Pattern/Stock.class -------------------------------------------------------------------------------- /Command Pattern/src/Broker.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | public class Broker { 8 | private List orderList = new ArrayList(); 9 | 10 | public void takeOrder(Order order){ 11 | orderList.add(order); 12 | } 13 | 14 | public void placeOrders(){ 15 | 16 | for (Order order : orderList) { 17 | order.execute(); 18 | } 19 | orderList.clear(); 20 | } 21 | } -------------------------------------------------------------------------------- /Command Pattern/src/BuyStock.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class BuyStock implements Order { 5 | private Stock abcStock; 6 | 7 | public BuyStock(Stock abcStock){ 8 | this.abcStock = abcStock; 9 | } 10 | 11 | public void execute() { 12 | abcStock.buy(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Command Pattern/src/CommandPatternDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class CommandPatternDemo { 5 | public static void main(String[] args) { 6 | Stock abcStock = new Stock(); 7 | 8 | BuyStock buyStockOrder = new BuyStock(abcStock); 9 | SellStock sellStockOrder = new SellStock(abcStock); 10 | 11 | Broker broker = new Broker(); 12 | broker.takeOrder(buyStockOrder); 13 | broker.takeOrder(sellStockOrder); 14 | 15 | broker.placeOrders(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Command Pattern/src/Order.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public interface Order { 5 | void execute(); 6 | } 7 | -------------------------------------------------------------------------------- /Command Pattern/src/SellStock.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class SellStock implements Order { 5 | private Stock abcStock; 6 | 7 | public SellStock(Stock abcStock){ 8 | this.abcStock = abcStock; 9 | } 10 | 11 | public void execute() { 12 | abcStock.sell(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Command Pattern/src/Stock.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class Stock { 5 | private String name = "ABC"; 6 | private int quantity = 10; 7 | 8 | public void buy(){ 9 | System.out.println("Stock [ Name: "+name+" Quantity: " + quantity +" ] bought"); 10 | } 11 | public void sell(){ 12 | System.out.println("Stock [ Name: "+name+ "Quantity: " + quantity + "] sold"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Composite Pattern/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Composite Pattern/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Composite Pattern/Composite Pattern.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Composite Pattern/out/production/Composite Pattern/CompositePatternDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Composite Pattern/out/production/Composite Pattern/CompositePatternDemo.class -------------------------------------------------------------------------------- /Composite Pattern/out/production/Composite Pattern/Employee.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Composite Pattern/out/production/Composite Pattern/Employee.class -------------------------------------------------------------------------------- /Composite Pattern/src/CompositePatternDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class CompositePatternDemo { 5 | public static void main(String[] args) { 6 | 7 | Employee CEO = new Employee("John","CEO", 30000); 8 | 9 | Employee headSales = new Employee("Robert","Head Sales", 20000); 10 | 11 | Employee headMarketing = new Employee("Michel","Head Marketing", 20000); 12 | 13 | Employee clerk1 = new Employee("Laura","Marketing", 10000); 14 | Employee clerk2 = new Employee("Bob","Marketing", 10000); 15 | 16 | Employee salesExecutive1 = new Employee("Richard","Sales", 10000); 17 | Employee salesExecutive2 = new Employee("Rob","Sales", 10000); 18 | 19 | CEO.add(headSales); 20 | CEO.add(headMarketing); 21 | 22 | headSales.add(salesExecutive1); 23 | headSales.add(salesExecutive2); 24 | 25 | headMarketing.add(clerk1); 26 | headMarketing.add(clerk2); 27 | 28 | //print all employees of the organization 29 | System.out.println(CEO); 30 | 31 | for (Employee headEmployee : CEO.getSubordinates()) { 32 | System.out.println(headEmployee); 33 | 34 | for (Employee employee : headEmployee.getSubordinates()) { 35 | System.out.println(employee); 36 | } 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Composite Pattern/src/Employee.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | public class Employee { 8 | private String name; 9 | private String dept; 10 | private int salary; 11 | private List subordinates; 12 | 13 | // constructor 14 | public Employee(String name,String dept, int sal) { 15 | this.name = name; 16 | this.dept = dept; 17 | this.salary = sal; 18 | subordinates = new ArrayList(); 19 | } 20 | 21 | public void add(Employee e) { 22 | subordinates.add(e); 23 | } 24 | 25 | public void remove(Employee e) { 26 | subordinates.remove(e); 27 | } 28 | 29 | public List getSubordinates(){ 30 | return subordinates; 31 | } 32 | 33 | public String toString(){ 34 | return ("Employee :[ Name : " + name + ", dept : " + dept + ", salary :" + salary+" ]"); 35 | } 36 | } -------------------------------------------------------------------------------- /Decorator Pattern/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Decorator Pattern/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Decorator Pattern/Decorator Pattern.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Decorator Pattern/out/production/Decorator Pattern/Circle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Decorator Pattern/out/production/Decorator Pattern/Circle.class -------------------------------------------------------------------------------- /Decorator Pattern/out/production/Decorator Pattern/DecoratorPatternDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Decorator Pattern/out/production/Decorator Pattern/DecoratorPatternDemo.class -------------------------------------------------------------------------------- /Decorator Pattern/out/production/Decorator Pattern/Rectangle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Decorator Pattern/out/production/Decorator Pattern/Rectangle.class -------------------------------------------------------------------------------- /Decorator Pattern/out/production/Decorator Pattern/RedShapeDecorator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Decorator Pattern/out/production/Decorator Pattern/RedShapeDecorator.class -------------------------------------------------------------------------------- /Decorator Pattern/out/production/Decorator Pattern/Shape.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Decorator Pattern/out/production/Decorator Pattern/Shape.class -------------------------------------------------------------------------------- /Decorator Pattern/out/production/Decorator Pattern/ShapeDecorator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Decorator Pattern/out/production/Decorator Pattern/ShapeDecorator.class -------------------------------------------------------------------------------- /Decorator Pattern/src/Circle.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class Circle implements Shape { 5 | 6 | @Override 7 | public void draw() { 8 | System.out.println("Shape: Circle"); 9 | } 10 | } -------------------------------------------------------------------------------- /Decorator Pattern/src/DecoratorPatternDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class DecoratorPatternDemo { 5 | public static void main(String[] args) { 6 | 7 | Shape circle = new Circle(); 8 | 9 | Shape redCircle = new RedShapeDecorator(new Circle()); 10 | 11 | Shape redRectangle = new RedShapeDecorator(new Rectangle()); 12 | System.out.println("Circle with normal border"); 13 | circle.draw(); 14 | 15 | System.out.println("\nCircle of red border"); 16 | redCircle.draw(); 17 | 18 | System.out.println("\nRectangle of red border"); 19 | redRectangle.draw(); 20 | } 21 | } -------------------------------------------------------------------------------- /Decorator Pattern/src/Rectangle.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class Rectangle implements Shape { 5 | 6 | @Override 7 | public void draw() { 8 | System.out.println("Shape: Rectangle"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Decorator Pattern/src/RedShapeDecorator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class RedShapeDecorator extends ShapeDecorator { 5 | 6 | public RedShapeDecorator(Shape decoratedShape) { 7 | super(decoratedShape); 8 | } 9 | 10 | @Override 11 | public void draw() { 12 | decoratedShape.draw(); 13 | setRedBorder(decoratedShape); 14 | } 15 | 16 | private void setRedBorder(Shape decoratedShape){ 17 | System.out.println("Border Color: Red"); 18 | } 19 | } -------------------------------------------------------------------------------- /Decorator Pattern/src/Shape.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public interface Shape { 5 | void draw(); 6 | } 7 | -------------------------------------------------------------------------------- /Decorator Pattern/src/ShapeDecorator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public abstract class ShapeDecorator implements Shape { 5 | protected Shape decoratedShape; 6 | 7 | public ShapeDecorator(Shape decoratedShape){ 8 | this.decoratedShape = decoratedShape; 9 | } 10 | 11 | public void draw(){ 12 | decoratedShape.draw(); 13 | } 14 | } -------------------------------------------------------------------------------- /Facade Pattern/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Facade Pattern/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Facade Pattern/Facade Pattern.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Facade Pattern/out/production/Facade Pattern/Circle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Facade Pattern/out/production/Facade Pattern/Circle.class -------------------------------------------------------------------------------- /Facade Pattern/out/production/Facade Pattern/FacadePatternDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Facade Pattern/out/production/Facade Pattern/FacadePatternDemo.class -------------------------------------------------------------------------------- /Facade Pattern/out/production/Facade Pattern/Rectangle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Facade Pattern/out/production/Facade Pattern/Rectangle.class -------------------------------------------------------------------------------- /Facade Pattern/out/production/Facade Pattern/Shape.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Facade Pattern/out/production/Facade Pattern/Shape.class -------------------------------------------------------------------------------- /Facade Pattern/out/production/Facade Pattern/ShapeMaker.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Facade Pattern/out/production/Facade Pattern/ShapeMaker.class -------------------------------------------------------------------------------- /Facade Pattern/out/production/Facade Pattern/Square.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Facade Pattern/out/production/Facade Pattern/Square.class -------------------------------------------------------------------------------- /Facade Pattern/src/Circle.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class Circle implements Shape { 5 | 6 | @Override 7 | public void draw() { 8 | System.out.println("Circle::draw()"); 9 | } 10 | } -------------------------------------------------------------------------------- /Facade Pattern/src/FacadePatternDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class FacadePatternDemo { 5 | public static void main(String[] args) { 6 | ShapeMaker shapeMaker = new ShapeMaker(); 7 | 8 | shapeMaker.drawCircle(); 9 | shapeMaker.drawRectangle(); 10 | shapeMaker.drawSquare(); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Facade Pattern/src/Rectangle.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class Rectangle implements Shape { 5 | 6 | @Override 7 | public void draw() { 8 | System.out.println("Rectangle: draw()"); 9 | } 10 | } -------------------------------------------------------------------------------- /Facade Pattern/src/Shape.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public interface Shape { 5 | void draw(); 6 | } 7 | -------------------------------------------------------------------------------- /Facade Pattern/src/ShapeMaker.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class ShapeMaker { 5 | 6 | private Shape circle; 7 | private Shape rectangle; 8 | private Shape square; 9 | 10 | public ShapeMaker() { 11 | circle = new Circle(); 12 | rectangle = new Rectangle(); 13 | square = new Square(); 14 | } 15 | 16 | public void drawCircle(){ 17 | circle.draw(); 18 | } 19 | public void drawRectangle(){ 20 | rectangle.draw(); 21 | } 22 | public void drawSquare(){ 23 | square.draw(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Facade Pattern/src/Square.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class Square implements Shape { 5 | 6 | @Override 7 | public void draw() { 8 | System.out.println("Square::draw()"); 9 | } 10 | } -------------------------------------------------------------------------------- /Factory Pattern/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Factory Pattern/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Factory Pattern/Factory Pattern.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Factory Pattern/out/production/Factory Pattern/App.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Factory Pattern/out/production/Factory Pattern/App.class -------------------------------------------------------------------------------- /Factory Pattern/out/production/Factory Pattern/Circle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Factory Pattern/out/production/Factory Pattern/Circle.class -------------------------------------------------------------------------------- /Factory Pattern/out/production/Factory Pattern/Rectangle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Factory Pattern/out/production/Factory Pattern/Rectangle.class -------------------------------------------------------------------------------- /Factory Pattern/out/production/Factory Pattern/Shape.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Factory Pattern/out/production/Factory Pattern/Shape.class -------------------------------------------------------------------------------- /Factory Pattern/out/production/Factory Pattern/ShapeFactory.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Factory Pattern/out/production/Factory Pattern/ShapeFactory.class -------------------------------------------------------------------------------- /Factory Pattern/out/production/Factory Pattern/Square.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Factory Pattern/out/production/Factory Pattern/Square.class -------------------------------------------------------------------------------- /Factory Pattern/src/App.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class App { 5 | public static void main(String[] args) { 6 | ShapeFactory shapeFactory = new ShapeFactory(); 7 | 8 | // Daire seklini cizmek icin yontemi cagiriyoruz 9 | Shape shape1 = shapeFactory.getShape("CIRCLE"); 10 | 11 | // daireyi ciziyoruz. 12 | shape1.draw(); 13 | 14 | // Dikdörtgen seklini cizmek icin yontemi cagiriyoruz 15 | Shape shape2 = shapeFactory.getShape("RECTANGLE"); 16 | 17 | // Dikdörtgeni ciziyoruz. 18 | shape2.draw(); 19 | 20 | // Kare seklini cizmek icin yontemi cagiriyoruz 21 | Shape shape3 = shapeFactory.getShape("SQUARE"); 22 | 23 | // Kareyi ciziyoruz. 24 | shape3.draw(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Factory Pattern/src/Circle.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class Circle implements Shape { 5 | @Override 6 | public void draw() { 7 | System.out.println("Inside Circle: draw() method."); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Factory Pattern/src/Rectangle.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class Rectangle implements Shape { 5 | @Override 6 | public void draw() { 7 | System.out.println("Inside Rectangle: draw() method."); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Factory Pattern/src/Shape.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public interface Shape { 5 | void draw(); 6 | } 7 | -------------------------------------------------------------------------------- /Factory Pattern/src/ShapeFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class ShapeFactory { 5 | // Nesnenin seklini almak icin getShape kullaniyoruz. 6 | public Shape getShape(String shapeType){ 7 | if (shapeType == null){ 8 | return null; 9 | } 10 | if (shapeType.equalsIgnoreCase("CIRCLE")){ 11 | return new Circle(); 12 | } 13 | else if (shapeType.equalsIgnoreCase("RECTANGLE")){ 14 | return new Rectangle(); 15 | } 16 | else if (shapeType.equalsIgnoreCase("SQUARE")){ 17 | return new Square(); 18 | } 19 | return null; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Factory Pattern/src/Square.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class Square implements Shape { 5 | @Override 6 | public void draw() { 7 | System.out.println("Inside Square: draw() method."); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Flyweight Pattern/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Flyweight Pattern/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Flyweight Pattern/Flyweight Pattern.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Flyweight Pattern/out/production/Flyweight Pattern/Circle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Flyweight Pattern/out/production/Flyweight Pattern/Circle.class -------------------------------------------------------------------------------- /Flyweight Pattern/out/production/Flyweight Pattern/FlyweightPatternDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Flyweight Pattern/out/production/Flyweight Pattern/FlyweightPatternDemo.class -------------------------------------------------------------------------------- /Flyweight Pattern/out/production/Flyweight Pattern/Shape.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Flyweight Pattern/out/production/Flyweight Pattern/Shape.class -------------------------------------------------------------------------------- /Flyweight Pattern/out/production/Flyweight Pattern/ShapeFactory.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Flyweight Pattern/out/production/Flyweight Pattern/ShapeFactory.class -------------------------------------------------------------------------------- /Flyweight Pattern/src/Circle.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class Circle implements Shape { 5 | private String color; 6 | private int x; 7 | private int y; 8 | private int radius; 9 | 10 | public Circle(String color){ 11 | this.color = color; 12 | } 13 | 14 | public void setX(int x) { 15 | this.x = x; 16 | } 17 | 18 | public void setY(int y) { 19 | this.y = y; 20 | } 21 | 22 | public void setRadius(int radius) { 23 | this.radius = radius; 24 | } 25 | 26 | @Override 27 | public void draw() { 28 | System.out.println("Circle: Draw() [Color : " + color + ", x : " + x + ", y :" + y + ", radius :" + radius); 29 | } 30 | } -------------------------------------------------------------------------------- /Flyweight Pattern/src/FlyweightPatternDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class FlyweightPatternDemo { 5 | private static final String colors[] = { "Red", "Green", "Blue", "White", "Black" }; 6 | public static void main(String[] args) { 7 | 8 | for(int i=0; i < 20; ++i) { 9 | Circle circle = (Circle)ShapeFactory.getCircle(getRandomColor()); 10 | circle.setX(getRandomX()); 11 | circle.setY(getRandomY()); 12 | circle.setRadius(100); 13 | circle.draw(); 14 | } 15 | } 16 | private static String getRandomColor() { 17 | return colors[(int)(Math.random()*colors.length)]; 18 | } 19 | private static int getRandomX() { 20 | return (int)(Math.random()*100 ); 21 | } 22 | private static int getRandomY() { 23 | return (int)(Math.random()*100); 24 | } 25 | } -------------------------------------------------------------------------------- /Flyweight Pattern/src/Shape.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public interface Shape { 5 | void draw(); 6 | } 7 | -------------------------------------------------------------------------------- /Flyweight Pattern/src/ShapeFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | import java.util.HashMap; 5 | 6 | public class ShapeFactory { 7 | private static final HashMap circleMap = new HashMap(); 8 | 9 | public static Shape getCircle(String color) { 10 | Circle circle = (Circle)circleMap.get(color); 11 | 12 | if(circle == null) { 13 | circle = new Circle(color); 14 | circleMap.put(color, circle); 15 | System.out.println("Creating circle of color : " + color); 16 | } 17 | return circle; 18 | } 19 | } -------------------------------------------------------------------------------- /Interpreter Pattern/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Interpreter Pattern/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Interpreter Pattern/Interpreter Pattern.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Interpreter Pattern/out/production/Interpreter Pattern/AndExpression.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Interpreter Pattern/out/production/Interpreter Pattern/AndExpression.class -------------------------------------------------------------------------------- /Interpreter Pattern/out/production/Interpreter Pattern/Expression.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Interpreter Pattern/out/production/Interpreter Pattern/Expression.class -------------------------------------------------------------------------------- /Interpreter Pattern/out/production/Interpreter Pattern/InterpreterPatternDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Interpreter Pattern/out/production/Interpreter Pattern/InterpreterPatternDemo.class -------------------------------------------------------------------------------- /Interpreter Pattern/out/production/Interpreter Pattern/OrExpression.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Interpreter Pattern/out/production/Interpreter Pattern/OrExpression.class -------------------------------------------------------------------------------- /Interpreter Pattern/out/production/Interpreter Pattern/TerminalExpression.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Interpreter Pattern/out/production/Interpreter Pattern/TerminalExpression.class -------------------------------------------------------------------------------- /Interpreter Pattern/src/AndExpression.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class AndExpression implements Expression { 5 | 6 | private Expression expr1 = null; 7 | private Expression expr2 = null; 8 | 9 | public AndExpression(Expression expr1, Expression expr2) { 10 | this.expr1 = expr1; 11 | this.expr2 = expr2; 12 | } 13 | 14 | @Override 15 | public boolean interpret(String context) { 16 | return expr1.interpret(context) && expr2.interpret(context); 17 | } 18 | } -------------------------------------------------------------------------------- /Interpreter Pattern/src/Expression.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public interface Expression { 5 | public boolean interpret(String context); 6 | } 7 | -------------------------------------------------------------------------------- /Interpreter Pattern/src/InterpreterPatternDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class InterpreterPatternDemo { 5 | //Rule: Robert and John are male 6 | public static Expression getMaleExpression(){ 7 | Expression robert = new TerminalExpression("Robert"); 8 | Expression john = new TerminalExpression("John"); 9 | return new OrExpression(robert, john); 10 | } 11 | 12 | //Rule: Julie is a married women 13 | public static Expression getMarriedWomanExpression(){ 14 | Expression julie = new TerminalExpression("Julie"); 15 | Expression married = new TerminalExpression("Married"); 16 | return new AndExpression(julie, married); 17 | } 18 | 19 | public static void main(String[] args) { 20 | Expression isMale = getMaleExpression(); 21 | Expression isMarriedWoman = getMarriedWomanExpression(); 22 | 23 | System.out.println("John is male? " + isMale.interpret("John")); 24 | System.out.println("Julie is a married women? " + isMarriedWoman.interpret("Married Julie")); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Interpreter Pattern/src/OrExpression.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class OrExpression implements Expression { 5 | 6 | private Expression expr1 = null; 7 | private Expression expr2 = null; 8 | 9 | public OrExpression(Expression expr1, Expression expr2) { 10 | this.expr1 = expr1; 11 | this.expr2 = expr2; 12 | } 13 | 14 | @Override 15 | public boolean interpret(String context) { 16 | return expr1.interpret(context) || expr2.interpret(context); 17 | } 18 | } -------------------------------------------------------------------------------- /Interpreter Pattern/src/TerminalExpression.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class TerminalExpression implements Expression { 5 | 6 | private String data; 7 | 8 | public TerminalExpression(String data){ 9 | this.data = data; 10 | } 11 | 12 | @Override 13 | public boolean interpret(String context) { 14 | 15 | if(context.contains(data)){ 16 | return true; 17 | } 18 | return false; 19 | } 20 | } -------------------------------------------------------------------------------- /Iterator Pattern/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Iterator Pattern/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Iterator Pattern/Iterator Pattern.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Iterator Pattern/out/production/Iterator Pattern/Container.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Iterator Pattern/out/production/Iterator Pattern/Container.class -------------------------------------------------------------------------------- /Iterator Pattern/out/production/Iterator Pattern/Iterator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Iterator Pattern/out/production/Iterator Pattern/Iterator.class -------------------------------------------------------------------------------- /Iterator Pattern/out/production/Iterator Pattern/IteratorPatternDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Iterator Pattern/out/production/Iterator Pattern/IteratorPatternDemo.class -------------------------------------------------------------------------------- /Iterator Pattern/out/production/Iterator Pattern/NameRepository$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Iterator Pattern/out/production/Iterator Pattern/NameRepository$1.class -------------------------------------------------------------------------------- /Iterator Pattern/out/production/Iterator Pattern/NameRepository$NameIterator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Iterator Pattern/out/production/Iterator Pattern/NameRepository$NameIterator.class -------------------------------------------------------------------------------- /Iterator Pattern/out/production/Iterator Pattern/NameRepository.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Iterator Pattern/out/production/Iterator Pattern/NameRepository.class -------------------------------------------------------------------------------- /Iterator Pattern/src/Container.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public interface Container { 5 | public Iterator getIterator(); 6 | } 7 | -------------------------------------------------------------------------------- /Iterator Pattern/src/Iterator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public interface Iterator { 5 | public boolean hasNext(); 6 | public Object next(); 7 | } 8 | -------------------------------------------------------------------------------- /Iterator Pattern/src/IteratorPatternDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class IteratorPatternDemo { 5 | public static void main(String[] args) { 6 | NameRepository namesRepository = new NameRepository(); 7 | 8 | for(Iterator iter = namesRepository.getIterator(); iter.hasNext();){ 9 | String name = (String)iter.next(); 10 | System.out.println("Name : " + name); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Iterator Pattern/src/NameRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class NameRepository implements Container { 5 | public String names[] = {"Robert" , "John" ,"Julie" , "Lora"}; 6 | 7 | @Override 8 | public Iterator getIterator() { 9 | return new NameIterator(); 10 | } 11 | 12 | private class NameIterator implements Iterator { 13 | 14 | int index; 15 | 16 | @Override 17 | public boolean hasNext() { 18 | 19 | if(index < names.length){ 20 | return true; 21 | } 22 | return false; 23 | } 24 | 25 | @Override 26 | public Object next() { 27 | 28 | if(this.hasNext()){ 29 | return names[index++]; 30 | } 31 | return null; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Mediator Pattern/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Mediator Pattern/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Mediator Pattern/Mediator Pattern.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Mediator Pattern/out/production/Mediator Pattern/ChatRoom.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Mediator Pattern/out/production/Mediator Pattern/ChatRoom.class -------------------------------------------------------------------------------- /Mediator Pattern/out/production/Mediator Pattern/MediatorPatternDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Mediator Pattern/out/production/Mediator Pattern/MediatorPatternDemo.class -------------------------------------------------------------------------------- /Mediator Pattern/out/production/Mediator Pattern/User.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Mediator Pattern/out/production/Mediator Pattern/User.class -------------------------------------------------------------------------------- /Mediator Pattern/src/ChatRoom.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | import java.util.Date; 5 | 6 | public class ChatRoom { 7 | public static void showMessage(User user, String message){ 8 | System.out.println(new Date().toString() + " [" + user.getName() + "] : " + message); 9 | } 10 | } -------------------------------------------------------------------------------- /Mediator Pattern/src/MediatorPatternDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class MediatorPatternDemo { 5 | public static void main(String[] args) { 6 | User robert = new User("Robert"); 7 | User john = new User("John"); 8 | 9 | robert.sendMessage("Hi! John!"); 10 | john.sendMessage("Hello! Robert!"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Mediator Pattern/src/User.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class User { 5 | private String name; 6 | 7 | public String getName() { 8 | return name; 9 | } 10 | 11 | public void setName(String name) { 12 | this.name = name; 13 | } 14 | 15 | public User(String name){ 16 | this.name = name; 17 | } 18 | 19 | public void sendMessage(String message){ 20 | ChatRoom.showMessage(this,message); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Memento Pattern/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Memento Pattern/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Memento Pattern/Memento Pattern.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Memento Pattern/out/production/Memento Pattern/CareTaker.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Memento Pattern/out/production/Memento Pattern/CareTaker.class -------------------------------------------------------------------------------- /Memento Pattern/out/production/Memento Pattern/Memento.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Memento Pattern/out/production/Memento Pattern/Memento.class -------------------------------------------------------------------------------- /Memento Pattern/out/production/Memento Pattern/MementoPatternDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Memento Pattern/out/production/Memento Pattern/MementoPatternDemo.class -------------------------------------------------------------------------------- /Memento Pattern/out/production/Memento Pattern/Originator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Memento Pattern/out/production/Memento Pattern/Originator.class -------------------------------------------------------------------------------- /Memento Pattern/src/CareTaker.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | public class CareTaker { 8 | private List mementoList = new ArrayList(); 9 | 10 | public void add(Memento state){ 11 | mementoList.add(state); 12 | } 13 | 14 | public Memento get(int index){ 15 | return mementoList.get(index); 16 | } 17 | } -------------------------------------------------------------------------------- /Memento Pattern/src/Memento.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class Memento { 5 | private String state; 6 | 7 | public Memento(String state){ 8 | this.state = state; 9 | } 10 | 11 | public String getState(){ 12 | return state; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Memento Pattern/src/MementoPatternDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class MementoPatternDemo { 5 | public static void main(String[] args) { 6 | 7 | Originator originator = new Originator(); 8 | CareTaker careTaker = new CareTaker(); 9 | 10 | originator.setState("State #1"); 11 | originator.setState("State #2"); 12 | careTaker.add(originator.saveStateToMemento()); 13 | 14 | originator.setState("State #3"); 15 | careTaker.add(originator.saveStateToMemento()); 16 | 17 | originator.setState("State #4"); 18 | System.out.println("Current State: " + originator.getState()); 19 | 20 | originator.getStateFromMemento(careTaker.get(0)); 21 | System.out.println("First saved State: " + originator.getState()); 22 | originator.getStateFromMemento(careTaker.get(1)); 23 | System.out.println("Second saved State: " + originator.getState()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Memento Pattern/src/Originator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class Originator { 5 | private String state; 6 | 7 | public void setState(String state){ 8 | this.state = state; 9 | } 10 | 11 | public String getState(){ 12 | return state; 13 | } 14 | 15 | public Memento saveStateToMemento(){ 16 | return new Memento(state); 17 | } 18 | 19 | public void getStateFromMemento(Memento memento){ 20 | state = memento.getState(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Observer Pattern/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Observer Pattern/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Observer Pattern/Observer Pattern.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Observer Pattern/out/production/Observer Pattern/BinaryObserver.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Observer Pattern/out/production/Observer Pattern/BinaryObserver.class -------------------------------------------------------------------------------- /Observer Pattern/out/production/Observer Pattern/HexaObserver.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Observer Pattern/out/production/Observer Pattern/HexaObserver.class -------------------------------------------------------------------------------- /Observer Pattern/out/production/Observer Pattern/Observer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Observer Pattern/out/production/Observer Pattern/Observer.class -------------------------------------------------------------------------------- /Observer Pattern/out/production/Observer Pattern/ObserverPatternDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Observer Pattern/out/production/Observer Pattern/ObserverPatternDemo.class -------------------------------------------------------------------------------- /Observer Pattern/out/production/Observer Pattern/OctalObserver.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Observer Pattern/out/production/Observer Pattern/OctalObserver.class -------------------------------------------------------------------------------- /Observer Pattern/out/production/Observer Pattern/Subject.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Observer Pattern/out/production/Observer Pattern/Subject.class -------------------------------------------------------------------------------- /Observer Pattern/src/BinaryObserver.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class BinaryObserver extends Observer{ 5 | 6 | public BinaryObserver(Subject subject){ 7 | this.subject = subject; 8 | this.subject.attach(this); 9 | } 10 | 11 | @Override 12 | public void update() { 13 | System.out.println( "Binary String: " + Integer.toBinaryString( subject.getState() ) ); 14 | } 15 | } -------------------------------------------------------------------------------- /Observer Pattern/src/HexaObserver.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class HexaObserver extends Observer{ 5 | 6 | public HexaObserver(Subject subject){ 7 | this.subject = subject; 8 | this.subject.attach(this); 9 | } 10 | 11 | @Override 12 | public void update() { 13 | System.out.println( "Hex String: " + Integer.toHexString( subject.getState() ).toUpperCase() ); 14 | } 15 | } -------------------------------------------------------------------------------- /Observer Pattern/src/Observer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public abstract class Observer { 5 | protected Subject subject; 6 | public abstract void update(); 7 | } -------------------------------------------------------------------------------- /Observer Pattern/src/ObserverPatternDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class ObserverPatternDemo { 5 | public static void main(String[] args) { 6 | Subject subject = new Subject(); 7 | 8 | new HexaObserver(subject); 9 | new OctalObserver(subject); 10 | new BinaryObserver(subject); 11 | 12 | System.out.println("First state change: 15"); 13 | subject.setState(15); 14 | System.out.println("Second state change: 10"); 15 | subject.setState(10); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Observer Pattern/src/OctalObserver.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class OctalObserver extends Observer{ 5 | 6 | public OctalObserver(Subject subject){ 7 | this.subject = subject; 8 | this.subject.attach(this); 9 | } 10 | 11 | @Override 12 | public void update() { 13 | System.out.println( "Octal String: " + Integer.toOctalString( subject.getState() ) ); 14 | } 15 | } -------------------------------------------------------------------------------- /Observer Pattern/src/Subject.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | public class Subject { 8 | 9 | private List observers = new ArrayList(); 10 | private int state; 11 | 12 | public int getState() { 13 | return state; 14 | } 15 | 16 | public void setState(int state) { 17 | this.state = state; 18 | notifyAllObservers(); 19 | } 20 | 21 | public void attach(Observer observer){ 22 | observers.add(observer); 23 | } 24 | 25 | public void notifyAllObservers(){ 26 | for (Observer observer : observers) { 27 | observer.update(); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Prototype/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Prototype/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Prototype/Prototype.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Prototype/out/production/Prototype/App.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Prototype/out/production/Prototype/App.class -------------------------------------------------------------------------------- /Prototype/out/production/Prototype/Circle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Prototype/out/production/Prototype/Circle.class -------------------------------------------------------------------------------- /Prototype/out/production/Prototype/Rectangle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Prototype/out/production/Prototype/Rectangle.class -------------------------------------------------------------------------------- /Prototype/out/production/Prototype/Shape.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Prototype/out/production/Prototype/Shape.class -------------------------------------------------------------------------------- /Prototype/out/production/Prototype/ShapeCache.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Prototype/out/production/Prototype/ShapeCache.class -------------------------------------------------------------------------------- /Prototype/out/production/Prototype/Square.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Prototype/out/production/Prototype/Square.class -------------------------------------------------------------------------------- /Prototype/src/App.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class App { 5 | public static void main(String[] args) { 6 | 7 | ShapeCache.loadCache(); 8 | 9 | Shape clonedShape = (Shape) ShapeCache.getShape("1"); 10 | System.out.println("Shape : " + clonedShape.getType()); 11 | 12 | Shape clonedShape2 = (Shape) ShapeCache.getShape("2"); 13 | System.out.println("Shape : " + clonedShape2.getType()); 14 | 15 | Shape clonedShape3 = (Shape) ShapeCache.getShape("3"); 16 | System.out.println("Shape : " + clonedShape3.getType()); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Prototype/src/Circle.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class Circle extends Shape { 5 | 6 | public Circle(){ 7 | type = "Circle"; 8 | } 9 | 10 | @Override 11 | public void draw() { 12 | System.out.println("Inside Circle::draw() method."); 13 | } 14 | } -------------------------------------------------------------------------------- /Prototype/src/Rectangle.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class Rectangle extends Shape { 5 | 6 | public Rectangle(){ 7 | type = "Rectangle"; 8 | } 9 | 10 | @Override 11 | public void draw() { 12 | System.out.println("Inside Rectangle::draw() method."); 13 | } 14 | } -------------------------------------------------------------------------------- /Prototype/src/Shape.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public abstract class Shape implements Cloneable { 5 | 6 | private String id; 7 | protected String type; 8 | 9 | abstract void draw(); 10 | 11 | public String getType(){ 12 | return type; 13 | } 14 | 15 | public String getId() { 16 | return id; 17 | } 18 | 19 | public void setId(String id) { 20 | this.id = id; 21 | } 22 | 23 | public Object clone() { 24 | Object clone = null; 25 | 26 | try { 27 | clone = super.clone(); 28 | 29 | } catch (CloneNotSupportedException e) { 30 | e.printStackTrace(); 31 | } 32 | 33 | return clone; 34 | } 35 | } -------------------------------------------------------------------------------- /Prototype/src/ShapeCache.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | import java.util.Hashtable; 5 | 6 | public class ShapeCache { 7 | 8 | private static Hashtable shapeMap = new Hashtable(); 9 | 10 | public static Shape getShape(String shapeId) { 11 | Shape cachedShape = shapeMap.get(shapeId); 12 | return (Shape) cachedShape.clone(); 13 | } 14 | 15 | // for each shape run database query and create shape 16 | // shapeMap.put(shapeKey, shape); 17 | // for example, we are adding three shapes 18 | 19 | public static void loadCache() { 20 | Circle circle = new Circle(); 21 | circle.setId("1"); 22 | shapeMap.put(circle.getId(),circle); 23 | 24 | Square square = new Square(); 25 | square.setId("2"); 26 | shapeMap.put(square.getId(),square); 27 | 28 | Rectangle rectangle = new Rectangle(); 29 | rectangle.setId("3"); 30 | shapeMap.put(rectangle.getId(), rectangle); 31 | } 32 | } -------------------------------------------------------------------------------- /Prototype/src/Square.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class Square extends Shape { 5 | 6 | public Square(){ 7 | type = "Square"; 8 | } 9 | 10 | @Override 11 | public void draw() { 12 | System.out.println("Inside Square::draw() method."); 13 | } 14 | } -------------------------------------------------------------------------------- /Proxy Pattern/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Proxy Pattern/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Proxy Pattern/Proxy Pattern.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Proxy Pattern/out/production/Proxy Pattern/Image.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Proxy Pattern/out/production/Proxy Pattern/Image.class -------------------------------------------------------------------------------- /Proxy Pattern/out/production/Proxy Pattern/ProxyImage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Proxy Pattern/out/production/Proxy Pattern/ProxyImage.class -------------------------------------------------------------------------------- /Proxy Pattern/out/production/Proxy Pattern/ProxyPatternDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Proxy Pattern/out/production/Proxy Pattern/ProxyPatternDemo.class -------------------------------------------------------------------------------- /Proxy Pattern/out/production/Proxy Pattern/RealImage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Proxy Pattern/out/production/Proxy Pattern/RealImage.class -------------------------------------------------------------------------------- /Proxy Pattern/src/Image.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public interface Image { 5 | void display(); 6 | } 7 | -------------------------------------------------------------------------------- /Proxy Pattern/src/ProxyImage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class ProxyImage implements Image{ 5 | 6 | private RealImage realImage; 7 | private String fileName; 8 | 9 | public ProxyImage(String fileName){ 10 | this.fileName = fileName; 11 | } 12 | 13 | @Override 14 | public void display() { 15 | if(realImage == null){ 16 | realImage = new RealImage(fileName); 17 | } 18 | realImage.display(); 19 | } 20 | } -------------------------------------------------------------------------------- /Proxy Pattern/src/ProxyPatternDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class ProxyPatternDemo { 5 | 6 | public static void main(String[] args) { 7 | Image image = new ProxyImage("test_10mb.jpg"); 8 | 9 | //image will be loaded from disk 10 | image.display(); 11 | System.out.println(""); 12 | 13 | //image will not be loaded from disk 14 | image.display(); 15 | } 16 | } -------------------------------------------------------------------------------- /Proxy Pattern/src/RealImage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 30.04.2017. 3 | */ 4 | public class RealImage implements Image { 5 | 6 | private String fileName; 7 | 8 | public RealImage(String fileName){ 9 | this.fileName = fileName; 10 | loadFromDisk(fileName); 11 | } 12 | 13 | @Override 14 | public void display() { 15 | System.out.println("Displaying " + fileName); 16 | } 17 | 18 | private void loadFromDisk(String fileName){ 19 | System.out.println("Loading " + fileName); 20 | } 21 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Design-Pattern 2 | Design Pattern Tutorial 3 | gokhanyavas.com 4 | -------------------------------------------------------------------------------- /Singleton/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Singleton/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Singleton/.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 13 | 14 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 52 | 53 | 54 | 57 | 58 | 59 | 65 | 66 | 67 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 96 | 97 | 100 | 101 | 102 | 103 | 106 | 107 | 110 | 111 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 135 | 136 | 137 | 142 | 143 | 144 | 170 | 171 | 172 | 197 | 198 | 205 | 206 | 207 | 220 | 221 | 222 | 229 | 232 | 234 | 235 | 236 | 237 | 238 | 239 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 278 | 279 | 280 | 291 | 292 | 293 | 303 | 304 | 311 | 312 | 313 | 314 | 332 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 351 | 352 | 353 | 354 | 1493479001426 355 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 398 | 399 | 400 | 401 | 402 | 403 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | -------------------------------------------------------------------------------- /Singleton/Singleton.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Singleton/out/production/Singleton/App.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Singleton/out/production/Singleton/App.class -------------------------------------------------------------------------------- /Singleton/out/production/Singleton/SingleObject.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Singleton/out/production/Singleton/SingleObject.class -------------------------------------------------------------------------------- /Singleton/src/App.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class App { 5 | public static void main(String[] args) { 6 | 7 | //illegal construct 8 | //Compile Time Error: The constructor SingleObject() is not visible 9 | //SingleObject object = new SingleObject(); 10 | 11 | //Get the only object available 12 | SingleObject object = SingleObject.getInstance(); 13 | 14 | //show the message 15 | object.showMessage(); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Singleton/src/SingleObject.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 29.04.2017. 3 | */ 4 | public class SingleObject { 5 | 6 | //create an object of SingleObject 7 | private static SingleObject instance = new SingleObject(); 8 | 9 | //make the constructor private so that this class cannot be 10 | //instantiated 11 | private SingleObject(){} 12 | 13 | //Get the only object available 14 | public static SingleObject getInstance(){ 15 | return instance; 16 | } 17 | 18 | public void showMessage(){ 19 | System.out.println("Hello World!"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /State Pattern/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /State Pattern/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /State Pattern/State Pattern.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /State Pattern/out/production/State Pattern/Context.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/State Pattern/out/production/State Pattern/Context.class -------------------------------------------------------------------------------- /State Pattern/out/production/State Pattern/StartState.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/State Pattern/out/production/State Pattern/StartState.class -------------------------------------------------------------------------------- /State Pattern/out/production/State Pattern/State.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/State Pattern/out/production/State Pattern/State.class -------------------------------------------------------------------------------- /State Pattern/out/production/State Pattern/StatePatternDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/State Pattern/out/production/State Pattern/StatePatternDemo.class -------------------------------------------------------------------------------- /State Pattern/out/production/State Pattern/StopState.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/State Pattern/out/production/State Pattern/StopState.class -------------------------------------------------------------------------------- /State Pattern/src/Context.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class Context { 5 | private State state; 6 | 7 | public Context(){ 8 | state = null; 9 | } 10 | 11 | public void setState(State state){ 12 | this.state = state; 13 | } 14 | 15 | public State getState(){ 16 | return state; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /State Pattern/src/StartState.java: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Created by gokhanyavas on 1.05.2017. 4 | */ 5 | public class StartState implements State { 6 | 7 | public void doAction(Context context) { 8 | System.out.println("Player is in start state"); 9 | context.setState(this); 10 | } 11 | 12 | public String toString(){ 13 | return "Start State"; 14 | } 15 | } -------------------------------------------------------------------------------- /State Pattern/src/State.java: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Created by gokhanyavas on 1.05.2017. 4 | */ 5 | public interface State { 6 | public void doAction(Context context); 7 | } 8 | -------------------------------------------------------------------------------- /State Pattern/src/StatePatternDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class StatePatternDemo { 5 | public static void main(String[] args) { 6 | Context context = new Context(); 7 | 8 | StartState startState = new StartState(); 9 | startState.doAction(context); 10 | 11 | System.out.println(context.getState().toString()); 12 | 13 | StopState stopState = new StopState(); 14 | stopState.doAction(context); 15 | 16 | System.out.println(context.getState().toString()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /State Pattern/src/StopState.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class StopState implements State { 5 | 6 | public void doAction(Context context) { 7 | System.out.println("Player is in stop state"); 8 | context.setState(this); 9 | } 10 | 11 | public String toString(){ 12 | return "Stop State"; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Strategy Pattern/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Strategy Pattern/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Strategy Pattern/Strategy Pattern.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Strategy Pattern/out/production/Strategy Pattern/Context.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Strategy Pattern/out/production/Strategy Pattern/Context.class -------------------------------------------------------------------------------- /Strategy Pattern/out/production/Strategy Pattern/OperationAdd.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Strategy Pattern/out/production/Strategy Pattern/OperationAdd.class -------------------------------------------------------------------------------- /Strategy Pattern/out/production/Strategy Pattern/OperationMultiply.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Strategy Pattern/out/production/Strategy Pattern/OperationMultiply.class -------------------------------------------------------------------------------- /Strategy Pattern/out/production/Strategy Pattern/OperationSubstract.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Strategy Pattern/out/production/Strategy Pattern/OperationSubstract.class -------------------------------------------------------------------------------- /Strategy Pattern/out/production/Strategy Pattern/Strategy.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Strategy Pattern/out/production/Strategy Pattern/Strategy.class -------------------------------------------------------------------------------- /Strategy Pattern/out/production/Strategy Pattern/StrategyPatternDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Strategy Pattern/out/production/Strategy Pattern/StrategyPatternDemo.class -------------------------------------------------------------------------------- /Strategy Pattern/src/Context.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class Context { 5 | private Strategy strategy; 6 | 7 | public Context(Strategy strategy){ 8 | this.strategy = strategy; 9 | } 10 | 11 | public int executeStrategy(int num1, int num2){ 12 | return strategy.doOperation(num1, num2); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Strategy Pattern/src/OperationAdd.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class OperationAdd implements Strategy{ 5 | @Override 6 | public int doOperation(int num1, int num2) { 7 | return num1 + num2; 8 | } 9 | } -------------------------------------------------------------------------------- /Strategy Pattern/src/OperationMultiply.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class OperationMultiply implements Strategy{ 5 | @Override 6 | public int doOperation(int num1, int num2) { 7 | return num1 * num2; 8 | } 9 | } -------------------------------------------------------------------------------- /Strategy Pattern/src/OperationSubstract.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class OperationSubstract implements Strategy{ 5 | @Override 6 | public int doOperation(int num1, int num2) { 7 | return num1 - num2; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Strategy Pattern/src/Strategy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public interface Strategy { 5 | public int doOperation(int num1, int num2); 6 | } 7 | -------------------------------------------------------------------------------- /Strategy Pattern/src/StrategyPatternDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class StrategyPatternDemo { 5 | public static void main(String[] args) { 6 | Context context = new Context(new OperationAdd()); 7 | System.out.println("10 + 5 = " + context.executeStrategy(10, 5)); 8 | 9 | context = new Context(new OperationSubstract()); 10 | System.out.println("10 - 5 = " + context.executeStrategy(10, 5)); 11 | 12 | context = new Context(new OperationMultiply()); 13 | System.out.println("10 * 5 = " + context.executeStrategy(10, 5)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Template Pattern/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Template Pattern/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Template Pattern/Template Pattern.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Template Pattern/out/production/Template Pattern/Cricket.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Template Pattern/out/production/Template Pattern/Cricket.class -------------------------------------------------------------------------------- /Template Pattern/out/production/Template Pattern/Football.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Template Pattern/out/production/Template Pattern/Football.class -------------------------------------------------------------------------------- /Template Pattern/out/production/Template Pattern/Game.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Template Pattern/out/production/Template Pattern/Game.class -------------------------------------------------------------------------------- /Template Pattern/out/production/Template Pattern/TemplatePatternDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Template Pattern/out/production/Template Pattern/TemplatePatternDemo.class -------------------------------------------------------------------------------- /Template Pattern/src/Cricket.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class Cricket extends Game { 5 | 6 | @Override 7 | void endPlay() { 8 | System.out.println("Cricket Game Finished!"); 9 | } 10 | 11 | @Override 12 | void initialize() { 13 | System.out.println("Cricket Game Initialized! Start playing."); 14 | } 15 | 16 | @Override 17 | void startPlay() { 18 | System.out.println("Cricket Game Started. Enjoy the game!"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Template Pattern/src/Football.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class Football extends Game { 5 | 6 | @Override 7 | void endPlay() { 8 | System.out.println("Football Game Finished!"); 9 | } 10 | 11 | @Override 12 | void initialize() { 13 | System.out.println("Football Game Initialized! Start playing."); 14 | } 15 | 16 | @Override 17 | void startPlay() { 18 | System.out.println("Football Game Started. Enjoy the game!"); 19 | } 20 | } -------------------------------------------------------------------------------- /Template Pattern/src/Game.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public abstract class Game { 5 | abstract void initialize(); 6 | abstract void startPlay(); 7 | abstract void endPlay(); 8 | 9 | //template method 10 | public final void play(){ 11 | 12 | //initialize the game 13 | initialize(); 14 | 15 | //start game 16 | startPlay(); 17 | 18 | //end game 19 | endPlay(); 20 | } 21 | } -------------------------------------------------------------------------------- /Template Pattern/src/TemplatePatternDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class TemplatePatternDemo { 5 | public static void main(String[] args) { 6 | 7 | Game game = new Cricket(); 8 | game.play(); 9 | System.out.println(); 10 | game = new Football(); 11 | game.play(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Visitor Pattern/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Visitor Pattern/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Visitor Pattern/Visitor Pattern.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Visitor Pattern/out/production/Visitor Pattern/Computer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Visitor Pattern/out/production/Visitor Pattern/Computer.class -------------------------------------------------------------------------------- /Visitor Pattern/out/production/Visitor Pattern/ComputerPart.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Visitor Pattern/out/production/Visitor Pattern/ComputerPart.class -------------------------------------------------------------------------------- /Visitor Pattern/out/production/Visitor Pattern/ComputerPartDisplayVisitor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Visitor Pattern/out/production/Visitor Pattern/ComputerPartDisplayVisitor.class -------------------------------------------------------------------------------- /Visitor Pattern/out/production/Visitor Pattern/ComputerPartVisitor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Visitor Pattern/out/production/Visitor Pattern/ComputerPartVisitor.class -------------------------------------------------------------------------------- /Visitor Pattern/out/production/Visitor Pattern/Keyboard.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Visitor Pattern/out/production/Visitor Pattern/Keyboard.class -------------------------------------------------------------------------------- /Visitor Pattern/out/production/Visitor Pattern/Monitor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Visitor Pattern/out/production/Visitor Pattern/Monitor.class -------------------------------------------------------------------------------- /Visitor Pattern/out/production/Visitor Pattern/Mouse.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Visitor Pattern/out/production/Visitor Pattern/Mouse.class -------------------------------------------------------------------------------- /Visitor Pattern/out/production/Visitor Pattern/VisitorPatternDemo.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokhanyavas/Design-Pattern/5290090199750e5a1f0b6ca12e175da913029f04/Visitor Pattern/out/production/Visitor Pattern/VisitorPatternDemo.class -------------------------------------------------------------------------------- /Visitor Pattern/src/Computer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class Computer extends ComputerPart { 5 | 6 | ComputerPart[] parts; 7 | 8 | public Computer(){ 9 | parts = new ComputerPart[] {new Mouse(), new Keyboard(), new Monitor()}; 10 | } 11 | 12 | 13 | @Override 14 | public void accept(ComputerPartVisitor computerPartVisitor) { 15 | for (int i = 0; i < parts.length; i++) { 16 | parts[i].accept(computerPartVisitor); 17 | } 18 | computerPartVisitor.visit(this); 19 | } 20 | } -------------------------------------------------------------------------------- /Visitor Pattern/src/ComputerPart.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class ComputerPart { 5 | public void accept(ComputerPartVisitor computerPartVisitor) { 6 | 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Visitor Pattern/src/ComputerPartDisplayVisitor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class ComputerPartDisplayVisitor implements ComputerPartVisitor { 5 | 6 | @Override 7 | public void visit(Computer computer) { 8 | System.out.println("Displaying Computer."); 9 | } 10 | 11 | @Override 12 | public void visit(Mouse mouse) { 13 | System.out.println("Displaying Mouse."); 14 | } 15 | 16 | @Override 17 | public void visit(Keyboard keyboard) { 18 | System.out.println("Displaying Keyboard."); 19 | } 20 | 21 | @Override 22 | public void visit(Monitor monitor) { 23 | System.out.println("Displaying Monitor."); 24 | } 25 | } -------------------------------------------------------------------------------- /Visitor Pattern/src/ComputerPartVisitor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public interface ComputerPartVisitor { 5 | public void visit(Computer computer); 6 | public void visit(Mouse mouse); 7 | public void visit(Keyboard keyboard); 8 | public void visit(Monitor monitor); 9 | } -------------------------------------------------------------------------------- /Visitor Pattern/src/Keyboard.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class Keyboard extends ComputerPart { 5 | 6 | @Override 7 | public void accept(ComputerPartVisitor computerPartVisitor) { 8 | computerPartVisitor.visit(this); 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /Visitor Pattern/src/Monitor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class Monitor extends ComputerPart { 5 | 6 | @Override 7 | public void accept(ComputerPartVisitor computerPartVisitor) { 8 | computerPartVisitor.visit(this); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Visitor Pattern/src/Mouse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class Mouse extends ComputerPart { 5 | 6 | @Override 7 | public void accept(ComputerPartVisitor computerPartVisitor) { 8 | computerPartVisitor.visit(this); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Visitor Pattern/src/VisitorPatternDemo.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by gokhanyavas on 1.05.2017. 3 | */ 4 | public class VisitorPatternDemo { 5 | public static void main(String[] args) { 6 | 7 | ComputerPart computer = new Computer(); 8 | computer.accept(new ComputerPartDisplayVisitor()); 9 | } 10 | } 11 | --------------------------------------------------------------------------------