From fba30e59ee8f0a82c577493ed0b2089ae4afae6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ilkka=20Sepp=C3=A4l=C3=A4?= Date: Sat, 12 Aug 2017 21:44:21 +0300 Subject: [PATCH] #590 Kramdown fixes --- factory-method/README.md | 5 ++++- singleton/README.md | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/factory-method/README.md b/factory-method/README.md index de3a9dd8c..07c92d0e5 100644 --- a/factory-method/README.md +++ b/factory-method/README.md @@ -20,14 +20,16 @@ decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses. ## Explanation - Real world example + > Blacksmith manufactures weapons. Elves require Elvish weapons and orcs require Orcish weapons. Depending on the customer at hand the right type of blacksmith is summoned. In plain words + > It provides a way to delegate the instantiation logic to child classes. Wikipedia says + > In class-based programming, the factory method pattern is a creational pattern that uses factory methods to deal with the problem of creating objects without having to specify the exact class of the object that will be created. This is done by creating objects by calling a factory method—either specified in an interface and implemented by child classes, or implemented in a base class and optionally overridden by derived classes—rather than by calling a constructor. **Programmatic Example** @@ -53,6 +55,7 @@ public class OrcBlacksmith implements Blacksmith { ``` Now as the customers come the correct type of blacksmith is summoned and requested weapons are manufactured + ``` Blacksmith blacksmith = new ElfBlacksmith(); blacksmith.manufactureWeapon(WeaponType.SPEAR); diff --git a/singleton/README.md b/singleton/README.md index 0a81ba0fc..1be304d8e 100644 --- a/singleton/README.md +++ b/singleton/README.md @@ -18,24 +18,31 @@ access to it. ## Explanation Real world example + > There can only be one ivory tower where the wizards study their magic. The same enchanted ivory tower is always used by the wizards. Ivory tower here is singleton. In plain words + > Ensures that only one object of a particular class is ever created. Wikipedia says + > In software engineering, the singleton pattern is a software design pattern that restricts the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system. **Programmatic Example** Joshua Bloch, Effective Java 2nd Edition p.18 + > A single-element enum type is the best way to implement a singleton + ``` public enum EnumIvoryTower { INSTANCE; } ``` + Then in order to use + ``` EnumIvoryTower enumIvoryTower1 = EnumIvoryTower.INSTANCE; EnumIvoryTower enumIvoryTower2 = EnumIvoryTower.INSTANCE;