diff --git a/README.md b/README.md index 7076345..93f7085 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,8 @@ Wikipedia describes them as ### ⚠️ 请注意 / Be Careful - Design patterns are not a silver bullet to all your problems. -- Do not try to force them bad things are supposed to happen, if done so. Keep in mind that design patterns are solutions **to** problems, not solutions **finding** problems so don't overthink. +- Do not try to force them; bad things are supposed to happen, if done so. +- Keep in mind that design patterns are solutions **to** problems, not solutions **finding** problems; so don't overthink. - If used in a correct place in a correct manner, they can prove to be a savior or else they can result in a horrible mess of a code. ### 🐢 在开始之前 / Before you start @@ -70,7 +71,7 @@ Wikipedia says ### 🏠 简单工厂模式 / Simple Factory Real world example -> Consider, you are building a house and you need doors. It would be a mess if every time you need a door, you put on your carpenter clothes and start making a door in your house. Instead you get it made from a factory. +> Consider, you are building a house and you need doors. You can either put on your carpenter clothes, bring some wood, glue, nails and all the tools required to build the door and start building it in your house or you can simply call the factory and get the built door delivered to you so that you don't need to learn anything about the door making or to deal with the mess that comes with making it. In plain words > Simple factory simply generates an instance for client without exposing any instantiation logic to the client @@ -83,13 +84,11 @@ Wikipedia says First of all we have a door interface and the implementation ```js -/* -Door - -getWidth() -getHeight() - -*/ +/** + * Door + * getWidth() + * getHeight() + */ class WoodenDoor { constructor(width, height){ @@ -118,9 +117,14 @@ const DoorFactory = { And then it can be used as ```js +// Make me a door of 100x200 const door = DoorFactory.makeDoor(100, 200) + console.log('Width:', door.getWidth()) console.log('Height:', door.getHeight()) + +// Make me a door of 50x100 +const door = DoorFactory.makeDoor(50, 100) ``` **When to Use?**