├── .gitignore ├── LICENSE ├── src └── main │ └── java │ └── me │ └── sumithpuri │ └── github │ └── phuket │ ├── command │ ├── AuctionItem.java │ ├── AuctionVase.java │ ├── AuctionJewel.java │ ├── AuctionFurniture.java │ ├── AuctionControl.java │ └── AuctionStore.java │ ├── factory │ ├── abstract_ │ │ ├── MobileMechanic.java │ │ ├── SonyASeries.java │ │ ├── SonyBSeries.java │ │ ├── NokiaASeries.java │ │ ├── NokiaBSeries.java │ │ ├── SonyCSeries.java │ │ ├── NokiaCSeries.java │ │ ├── LearningMechanicStoreFactory.java │ │ ├── RobotMechanicStoreFactory.java │ │ ├── CertifiedMechanicStoreFactory.java │ │ ├── RobotMechanic.java │ │ ├── CertifiedMechanic.java │ │ ├── LearningMechanic.java │ │ ├── MobileStoreFactoryMethod.java │ │ ├── Mobile.java │ │ ├── SonySimpleFactory.java │ │ ├── NokiaSimpleFactory.java │ │ ├── MobileStoreAbstractFactory.java │ │ └── MobileAbstractFactoryApp.java │ ├── simple │ │ ├── System.java │ │ ├── LinuxSystem.java │ │ ├── MacosSystem.java │ │ ├── UnixSystem.java │ │ ├── SolarisSystem.java │ │ ├── WindowsSystem.java │ │ ├── SystemManager.java │ │ └── SystemFactory.java │ └── method │ │ ├── SonyASeries.java │ │ ├── SonyBSeries.java │ │ ├── NokiaASeries.java │ │ ├── NokiaBSeries.java │ │ ├── SonyCSeries.java │ │ ├── NokiaCSeries.java │ │ ├── MobileStoreFactoryMethod.java │ │ ├── Mobile.java │ │ ├── SonySimpleFactory.java │ │ ├── NokiaSimpleFactory.java │ │ ├── MobileStoreFactory.java │ │ └── MobileFactoryApp.java │ ├── decorator │ ├── ToppingDecorator.java │ ├── Pizza.java │ ├── Italian.java │ ├── Mexican.java │ ├── Hawaiian.java │ ├── Onion.java │ ├── Chicken.java │ ├── Mushroom.java │ └── PizzaWorld.java │ ├── observer │ ├── Observer.java │ ├── Subject.java │ ├── IncomeHandler.java │ ├── PortfolioHandler.java │ ├── InvestmentHandler.java │ ├── StockBroker.java │ └── StockData.java │ ├── singleton │ ├── eager │ │ ├── ProductionHouse.java │ │ └── MediaContractUsingEager.java │ ├── threadsafe │ │ ├── ProductionHouse.java │ │ └── MediaContractUsingThreadSafe.java │ └── doublechecked │ │ ├── ProductionHouse.java │ │ └── MediaContractUsingDoubleChecked.java │ └── main │ └── gof_Phuket.java ├── pom.xml └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Sumith Kumar Puri 4 | 5 | [Refer Each Code File for the Actual Licence Statement] 6 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/command/AuctionItem.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.command; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public abstract class AuctionItem { 31 | 32 | public void sell() { 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/abstract_/MobileMechanic.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.abstract_; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public interface MobileMechanic { 31 | 32 | public abstract void preAssemblyCheck(); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/decorator/ToppingDecorator.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.decorator; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public abstract class ToppingDecorator extends Pizza { 31 | 32 | public abstract String getDescription(); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/observer/Observer.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.observer; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public interface Observer { 31 | 32 | public void update(String stockSymbol, Float stockValue, Integer stockUnits); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/command/AuctionVase.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.command; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class AuctionVase extends AuctionItem { 31 | 32 | public void sell() { 33 | System.out.println("Sold Vase Item"); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/command/AuctionJewel.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.command; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class AuctionJewel extends AuctionItem { 31 | 32 | public void sell() { 33 | System.out.println("Sold Jewel Item"); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/simple/System.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.simple; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public interface System { 31 | 32 | public void provision(); 33 | public void update(); 34 | public void restart(); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/method/SonyASeries.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.method; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class SonyASeries extends Mobile { 31 | 32 | public SonyASeries() { 33 | 34 | super("Sony", "A Series"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/method/SonyBSeries.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.method; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class SonyBSeries extends Mobile { 31 | 32 | public SonyBSeries() { 33 | 34 | super("Sony", "B Series"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/command/AuctionFurniture.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.command; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class AuctionFurniture extends AuctionItem { 31 | 32 | public void sell() { 33 | System.out.println("Sold Furniture Item"); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/abstract_/SonyASeries.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.abstract_; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class SonyASeries extends Mobile { 31 | 32 | public SonyASeries() { 33 | 34 | super("Sony", "A Series"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/abstract_/SonyBSeries.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.abstract_; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class SonyBSeries extends Mobile { 31 | 32 | public SonyBSeries() { 33 | 34 | super("Sony", "B Series"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/method/NokiaASeries.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.method; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class NokiaASeries extends Mobile { 31 | 32 | public NokiaASeries() { 33 | 34 | super("Nokia", "A Series"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/method/NokiaBSeries.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.method; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class NokiaBSeries extends Mobile { 31 | 32 | public NokiaBSeries() { 33 | 34 | super("Nokia", "B Series"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/method/SonyCSeries.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.method; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class SonyCSeries extends Mobile { 31 | 32 | public SonyCSeries() { 33 | 34 | super("Sony", "C Series"); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/abstract_/NokiaASeries.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.abstract_; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class NokiaASeries extends Mobile { 31 | 32 | public NokiaASeries() { 33 | 34 | super("Nokia", "A Series"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/abstract_/NokiaBSeries.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.abstract_; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class NokiaBSeries extends Mobile { 31 | 32 | public NokiaBSeries() { 33 | 34 | super("Nokia", "B Series"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/abstract_/SonyCSeries.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.abstract_; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class SonyCSeries extends Mobile { 31 | 32 | public SonyCSeries() { 33 | 34 | super("Sony", "C Series"); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/method/NokiaCSeries.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.method; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class NokiaCSeries extends Mobile { 31 | 32 | public NokiaCSeries() { 33 | 34 | super("Nokia", "C Series"); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/abstract_/NokiaCSeries.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.abstract_; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class NokiaCSeries extends Mobile { 31 | 32 | public NokiaCSeries() { 33 | 34 | super("Nokia", "C Series"); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/observer/Subject.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.observer; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public interface Subject { 31 | 32 | public void addObserver(Observer o); 33 | public void removeObserver(Observer o); 34 | public void notifyObservers(); 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/decorator/Pizza.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.decorator; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public abstract class Pizza { 31 | 32 | protected String description = null; 33 | 34 | public String getDescription() { 35 | return description; 36 | } 37 | 38 | public abstract double cost(); 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/abstract_/LearningMechanicStoreFactory.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.abstract_; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class LearningMechanicStoreFactory extends MobileStoreAbstractFactory { 31 | 32 | public LearningMechanicStoreFactory() { 33 | mobileMechanic = new LearningMechanic(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/abstract_/RobotMechanicStoreFactory.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.abstract_; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class RobotMechanicStoreFactory extends MobileStoreAbstractFactory { 31 | 32 | public RobotMechanicStoreFactory() { 33 | mobileMechanic = new RobotMechanic(); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/abstract_/CertifiedMechanicStoreFactory.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.abstract_; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class CertifiedMechanicStoreFactory extends MobileStoreAbstractFactory { 31 | 32 | public CertifiedMechanicStoreFactory() { 33 | mobileMechanic = new CertifiedMechanic(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/abstract_/RobotMechanic.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.abstract_; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class RobotMechanic implements MobileMechanic { 31 | 32 | @Override 33 | public void preAssemblyCheck() { 34 | 35 | System.out.println("Robot Mechanic: Pre-Assembly Check of Raw Materials!"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/decorator/Italian.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.decorator; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class Italian extends Pizza { 31 | 32 | public Italian(String description) { 33 | this.description = description + ", Italian"; 34 | } 35 | 36 | @Override 37 | public double cost() { 38 | 39 | return 1.20; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/decorator/Mexican.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.decorator; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class Mexican extends Pizza { 31 | 32 | public Mexican(String description) { 33 | this.description = description + ", Mexican"; 34 | } 35 | 36 | @Override 37 | public double cost() { 38 | 39 | return 1.25; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/abstract_/CertifiedMechanic.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.abstract_; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class CertifiedMechanic implements MobileMechanic { 31 | 32 | @Override 33 | public void preAssemblyCheck() { 34 | 35 | System.out.println("Certified Mechanic: Pre-Assembly Check of Raw Materials!"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/abstract_/LearningMechanic.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.abstract_; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class LearningMechanic implements MobileMechanic { 31 | 32 | @Override 33 | public void preAssemblyCheck() { 34 | 35 | System.out.println("Learning Mechanic: Pre-Assembly Check of Raw Materials!"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/decorator/Hawaiian.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.decorator; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class Hawaiian extends Pizza { 31 | 32 | public Hawaiian(String description) { 33 | this.description = description + ", Hawaiian"; 34 | } 35 | 36 | @Override 37 | public double cost() { 38 | 39 | return 1.50; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/singleton/eager/ProductionHouse.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.singleton.eager; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class ProductionHouse { 31 | 32 | private static ProductionHouse productionHouse = new ProductionHouse(); 33 | 34 | private ProductionHouse() { 35 | 36 | } 37 | 38 | public static synchronized ProductionHouse getInstance() { 39 | 40 | return productionHouse; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/method/MobileStoreFactoryMethod.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.method; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public abstract class MobileStoreFactoryMethod { 31 | 32 | public Mobile getMobileFactory(String make) { 33 | 34 | //factory method demonstration 35 | Mobile mobile; 36 | mobile = createMobile(make); 37 | return mobile; 38 | } 39 | 40 | //abstract method - the factory method 41 | protected abstract Mobile createMobile(String make); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/abstract_/MobileStoreFactoryMethod.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.abstract_; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public abstract class MobileStoreFactoryMethod { 31 | 32 | public Mobile getMobileFactory(String make) { 33 | 34 | //factory method demonstration 35 | Mobile mobile; 36 | mobile = createMobile(make); 37 | return mobile; 38 | } 39 | 40 | //abstract method - the factory method 41 | protected abstract Mobile createMobile(String make); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/simple/LinuxSystem.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.simple; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class LinuxSystem implements System { 31 | 32 | @Override 33 | public void provision() { 34 | // TODO Auto-generated method stub 35 | 36 | } 37 | 38 | @Override 39 | public void restart() { 40 | // TODO Auto-generated method stub 41 | 42 | } 43 | 44 | @Override 45 | public void update() { 46 | // TODO Auto-generated method stub 47 | 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/simple/MacosSystem.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.simple; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class MacosSystem implements System { 31 | 32 | @Override 33 | public void provision() { 34 | // TODO Auto-generated method stub 35 | 36 | } 37 | 38 | @Override 39 | public void restart() { 40 | // TODO Auto-generated method stub 41 | 42 | } 43 | 44 | @Override 45 | public void update() { 46 | // TODO Auto-generated method stub 47 | 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/simple/UnixSystem.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.simple; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class UnixSystem implements System { 31 | 32 | @Override 33 | public void provision() { 34 | // TODO Auto-generated method stub 35 | 36 | } 37 | 38 | @Override 39 | public void restart() { 40 | // TODO Auto-generated method stub 41 | 42 | } 43 | 44 | @Override 45 | public void update() { 46 | // TODO Auto-generated method stub 47 | 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/simple/SolarisSystem.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.simple; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class SolarisSystem implements System { 31 | 32 | @Override 33 | public void provision() { 34 | // TODO Auto-generated method stub 35 | 36 | } 37 | 38 | @Override 39 | public void restart() { 40 | // TODO Auto-generated method stub 41 | 42 | } 43 | 44 | @Override 45 | public void update() { 46 | // TODO Auto-generated method stub 47 | 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/simple/WindowsSystem.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.simple; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class WindowsSystem implements System { 31 | 32 | @Override 33 | public void provision() { 34 | // TODO Auto-generated method stub 35 | 36 | } 37 | 38 | @Override 39 | public void restart() { 40 | // TODO Auto-generated method stub 41 | 42 | } 43 | 44 | @Override 45 | public void update() { 46 | // TODO Auto-generated method stub 47 | 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/decorator/Onion.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.decorator; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class Onion extends ToppingDecorator { 31 | 32 | Pizza pizza; 33 | 34 | public Onion(Pizza pizza) { 35 | 36 | this.pizza = pizza; 37 | } 38 | 39 | @Override 40 | public String getDescription() { 41 | 42 | return pizza.getDescription() + ", Onion"; 43 | } 44 | 45 | @Override 46 | public double cost() { 47 | 48 | return (0.15 + pizza.cost()); 49 | } 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/observer/IncomeHandler.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.observer; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class IncomeHandler implements Observer { 31 | 32 | Subject stockData = null; 33 | 34 | public IncomeHandler(Subject stockData) { 35 | this.stockData = stockData; 36 | stockData.addObserver(this); 37 | } 38 | 39 | @Override 40 | public void update(String stockSymbol, Float stockValue, Integer stockUnits) { 41 | System.out.println("IncomeHandler: Received Notification... "); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/singleton/threadsafe/ProductionHouse.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.singleton.threadsafe; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class ProductionHouse { 31 | 32 | private static ProductionHouse productionHouse = null; 33 | 34 | private ProductionHouse() { 35 | 36 | } 37 | 38 | public static synchronized ProductionHouse getInstance() { 39 | 40 | if(productionHouse == null) { 41 | productionHouse = new ProductionHouse(); 42 | } 43 | 44 | return productionHouse; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/decorator/Chicken.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.decorator; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class Chicken extends ToppingDecorator { 31 | 32 | Pizza pizza; 33 | 34 | public Chicken(Pizza pizza) { 35 | 36 | this.pizza = pizza; 37 | } 38 | 39 | @Override 40 | public String getDescription() { 41 | 42 | return pizza.getDescription() + ", Chicken"; 43 | } 44 | 45 | @Override 46 | public double cost() { 47 | 48 | return 0.45 + pizza.cost(); 49 | } 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/decorator/Mushroom.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.decorator; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class Mushroom extends ToppingDecorator { 31 | 32 | Pizza pizza; 33 | 34 | public Mushroom(Pizza pizza) { 35 | 36 | this.pizza = pizza; 37 | } 38 | 39 | @Override 40 | public String getDescription() { 41 | 42 | return pizza.getDescription() + ", Mushroom"; 43 | } 44 | 45 | @Override 46 | public double cost() { 47 | 48 | return 0.25 + pizza.cost(); 49 | } 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/observer/PortfolioHandler.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.observer; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class PortfolioHandler implements Observer { 31 | 32 | Subject stockData = null; 33 | 34 | public PortfolioHandler(Subject stockData) { 35 | this.stockData = stockData; 36 | stockData.addObserver(this); 37 | } 38 | 39 | @Override 40 | public void update(String stockSymbol, Float stockValue, Integer stockUnits) { 41 | System.out.println("PortfolioHandler: Received Notification... "); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/observer/InvestmentHandler.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.observer; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class InvestmentHandler implements Observer { 31 | 32 | Subject stockData = null; 33 | 34 | public InvestmentHandler(Subject stockData) { 35 | this.stockData = stockData; 36 | stockData.addObserver(this); 37 | } 38 | 39 | @Override 40 | public void update(String stockSymbol, Float stockValue, Integer stockUnits) { 41 | System.out.println("InvestmentHandler: Received Notification... "); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/method/Mobile.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.method; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public abstract class Mobile { 31 | 32 | private String mobileMake= null; 33 | private String mobileSeries=null; 34 | 35 | public Mobile(String mobileMake, String mobileSeries) { 36 | super(); 37 | this.mobileMake = mobileMake; 38 | this.mobileSeries = mobileSeries; 39 | } 40 | 41 | public String getMobileMake() { 42 | return mobileMake; 43 | } 44 | 45 | public String getMobileSeries() { 46 | return mobileSeries; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/abstract_/Mobile.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.abstract_; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public abstract class Mobile { 31 | 32 | private String mobileMake= null; 33 | private String mobileSeries=null; 34 | 35 | public Mobile(String mobileMake, String mobileSeries) { 36 | super(); 37 | this.mobileMake = mobileMake; 38 | this.mobileSeries = mobileSeries; 39 | } 40 | 41 | public String getMobileMake() { 42 | return mobileMake; 43 | } 44 | 45 | public String getMobileSeries() { 46 | return mobileSeries; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/method/SonySimpleFactory.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.method; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class SonySimpleFactory extends MobileStoreFactoryMethod { 31 | 32 | @Override 33 | protected Mobile createMobile(String make) { 34 | Mobile mobile = null; 35 | 36 | if(make.equals("ASeries")) { 37 | mobile = new SonyASeries(); 38 | } else if(make.equals("BSeries")) { 39 | mobile = new SonyBSeries(); 40 | } else if(make.equals("CSeries")) { 41 | mobile = new SonyCSeries(); 42 | } 43 | 44 | return mobile; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/simple/SystemManager.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.simple; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class SystemManager { 31 | 32 | public static void main(String args[]) { 33 | 34 | demonstrate(); 35 | } 36 | 37 | public static void demonstrate() { 38 | 39 | // Either instantiate here, or inject instance in a constructor 40 | SystemFactory systemFactory = new SystemFactory(); 41 | 42 | System system = systemFactory.createSystem("MAC"); 43 | 44 | system.provision(); 45 | system.update(); 46 | system.restart(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/method/NokiaSimpleFactory.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.method; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class NokiaSimpleFactory extends MobileStoreFactoryMethod { 31 | 32 | @Override 33 | protected Mobile createMobile(String make) { 34 | Mobile mobile = null; 35 | 36 | if(make.equals("ASeries")) { 37 | mobile = new NokiaASeries(); 38 | } else if(make.equals("BSeries")) { 39 | mobile = new NokiaBSeries(); 40 | } else if(make.equals("CSeries")) { 41 | mobile = new NokiaCSeries(); 42 | } 43 | 44 | return mobile; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/command/AuctionControl.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.command; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * MIT License 8 | * 9 | * Copyright (c) 2018-19, Sumith Kumar Puri 10 | 11 | * GitHub URL https://github.com/sumithpuri 12 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 13 | * Blog Short URL https://goo.gl/kmSDiV 14 | * Package Prefix me.sumithpuri.github.phuket 15 | * Project Codename phuket 16 | * Contact E-Mail code@sumithpuri.me 17 | * Contact WhatsApp +91 9591497974 18 | * 19 | * 20 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 21 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 22 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 23 | * persons to whom the Software is furnished to do so, subject to the following conditions: 24 | * 25 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 26 | * Software. 27 | * 28 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 29 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 30 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 31 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | */ 33 | public class AuctionControl { 34 | 35 | Map auctionItems = new HashMap(); 36 | 37 | public void setAuctionItem(String itemKey, AuctionItem auctionItem) { 38 | 39 | auctionItems.put(itemKey, auctionItem); 40 | } 41 | 42 | public void presentItem(String itemKey) { 43 | 44 | AuctionItem auctionItem = auctionItems.get(itemKey); 45 | auctionItem.sell(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/method/MobileStoreFactory.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.method; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class MobileStoreFactory { 31 | 32 | public static MobileStoreFactoryMethod getMobileFactory(String make) { 33 | 34 | //factory method demonstration 35 | MobileStoreFactoryMethod mobileStoreFactory=null; 36 | 37 | if(make.equals("Nokia")) { 38 | mobileStoreFactory = new NokiaSimpleFactory(); 39 | } else if(make.equals("Sony")) { 40 | mobileStoreFactory = new SonySimpleFactory(); 41 | } 42 | 43 | return mobileStoreFactory; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/singleton/doublechecked/ProductionHouse.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.singleton.doublechecked; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class ProductionHouse { 31 | 32 | private static ProductionHouse productionHouse = null; 33 | 34 | private ProductionHouse() { 35 | 36 | } 37 | 38 | public static ProductionHouse getInstance() { 39 | 40 | if(productionHouse == null) { 41 | synchronized(ProductionHouse.class) { 42 | if(productionHouse == null) { 43 | productionHouse = new ProductionHouse(); 44 | } 45 | } 46 | } 47 | 48 | return productionHouse; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/simple/SystemFactory.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.simple; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class SystemFactory { 31 | 32 | public System createSystem(String type) { 33 | System system = null; 34 | if(type.equals("WIN")) { 35 | system = new WindowsSystem(); 36 | } else if (type.equals("LIN")) { 37 | system = new LinuxSystem(); 38 | } else if (type.equals("SOL")) { 39 | system = new SolarisSystem(); 40 | } else if (type.equals("MAC")) { 41 | system = new MacosSystem(); 42 | } else { 43 | system = new UnixSystem(); 44 | } 45 | 46 | return system; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/command/AuctionStore.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.command; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class AuctionStore { 31 | 32 | public static void main(String args[]) { 33 | 34 | demonstrate(); 35 | } 36 | 37 | public static void demonstrate() { 38 | 39 | AuctionControl auctionControl = new AuctionControl(); 40 | auctionControl.setAuctionItem("FURN", new AuctionFurniture()); 41 | auctionControl.setAuctionItem("VASE", new AuctionVase()); 42 | auctionControl.setAuctionItem("JEWL", new AuctionJewel()); 43 | 44 | auctionControl.presentItem("FURN"); 45 | auctionControl.presentItem("JEWL"); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/abstract_/SonySimpleFactory.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.abstract_; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class SonySimpleFactory extends MobileStoreFactoryMethod { 31 | 32 | MobileMechanic mobileMechanic = null; 33 | 34 | public SonySimpleFactory(MobileMechanic mobileMechanic) { 35 | this.mobileMechanic = mobileMechanic; 36 | } 37 | 38 | @Override 39 | protected Mobile createMobile(String type) { 40 | mobileMechanic.preAssemblyCheck(); 41 | 42 | Mobile mobile = null; 43 | 44 | if(type.equals("ASeries")) { 45 | mobile = new SonyASeries(); 46 | } else if(type.equals("BSeries")) { 47 | mobile = new SonyBSeries(); 48 | } else if(type.equals("CSeries")) { 49 | mobile = new SonyCSeries(); 50 | } 51 | 52 | return mobile; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | me.sumithpuri.github 7 | skp-code-marathon-phuket 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | Phuket : Design Patterns - Series I (Gang Of Four) 12 | http://maven.apache.org 13 | 14 | 15 | UTF-8 16 | 9 17 | 9 18 | false 19 | 20 | 21 | 22 | 23 | 24 | junit 25 | junit 26 | 3.8.1 27 | test 28 | 29 | 30 | 31 | 32 | 33 | 34 | org.apache.maven.plugins 35 | maven-compiler-plugin 36 | 3.6.1 37 | 38 | 39 | org.codehaus.mojo 40 | exec-maven-plugin 41 | 1.6.0 42 | 43 | 44 | test 45 | 46 | java 47 | 48 | 49 | me.sumithpuri.github.phuket.main.gof_Phuket 50 | true 51 | 52 | 53 | 54 | 55 | 56 | org.apache.maven.plugins 57 | maven-jar-plugin 58 | 3.1.0 59 | 60 | 61 | 62 | true 63 | me.sumithpuri.github.phuket.main.gof_Phuket 64 | 65 | 66 | 67 | 68 | 69 | 70 | Code Samples for the Blog Article [Design Patterns - Series I (Gang Of Four)] 71 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/abstract_/NokiaSimpleFactory.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.abstract_; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class NokiaSimpleFactory extends MobileStoreFactoryMethod { 31 | 32 | MobileMechanic mobileMechanic = null; 33 | 34 | public NokiaSimpleFactory(MobileMechanic mobileMechanic) { 35 | this.mobileMechanic = mobileMechanic; 36 | } 37 | 38 | @Override 39 | protected Mobile createMobile(String type) { 40 | 41 | mobileMechanic.preAssemblyCheck(); 42 | 43 | Mobile mobile = null; 44 | 45 | if(type.equals("ASeries")) { 46 | mobile = new NokiaASeries(); 47 | } else if(type.equals("BSeries")) { 48 | mobile = new NokiaBSeries(); 49 | } else if(type.equals("CSeries")) { 50 | mobile = new NokiaCSeries(); 51 | } 52 | 53 | return mobile; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/singleton/eager/MediaContractUsingEager.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.singleton.eager; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class MediaContractUsingEager extends Thread { 31 | 32 | 33 | public void run() { 34 | getProductionHouse(); 35 | } 36 | 37 | public void getProductionHouse() { 38 | ProductionHouse productionHouse = ProductionHouse.getInstance(); 39 | System.out.println(productionHouse.toString()); 40 | } 41 | 42 | public static void main(String args[]) throws Exception { 43 | 44 | demonstrate(); 45 | } 46 | 47 | public static void demonstrate() { 48 | 49 | MediaContractUsingEager thread01 = new MediaContractUsingEager(); 50 | thread01.start(); 51 | 52 | MediaContractUsingEager thread02 = new MediaContractUsingEager(); 53 | thread02.start(); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/observer/StockBroker.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.observer; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class StockBroker { 31 | 32 | public static void main(String args[]) { 33 | 34 | demonstrate(); 35 | } 36 | 37 | public static void demonstrate() { 38 | 39 | // Initialize Subject 40 | StockData stockData = new StockData(); 41 | 42 | // Initialize Observers, They Automatically Subscribe 43 | Observer incomeHandler = new IncomeHandler(stockData); 44 | Observer investmentHandler = new InvestmentHandler(stockData); 45 | Observer portfolioHandler = new PortfolioHandler(stockData); 46 | 47 | // Put it to work 48 | stockData.setStockData("GOOG", 489.50f, 10000); 49 | stockData.setStockData("MSFT", 231.25f, 1000000); 50 | stockData.setStockData("APPL", 9.63f, 2500000); 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/abstract_/MobileStoreAbstractFactory.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.abstract_; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public abstract class MobileStoreAbstractFactory { 31 | 32 | //not the most optimal way - to hide static variables! 33 | protected MobileMechanic mobileMechanic; 34 | 35 | public MobileStoreFactoryMethod getMobileFactory(String make) { 36 | 37 | //factory method demonstration 38 | MobileStoreFactoryMethod mobileStoreFactory=null; 39 | 40 | if(make.equals("Nokia")) { 41 | 42 | //abstract factory pattern 43 | mobileStoreFactory = new NokiaSimpleFactory(mobileMechanic); 44 | } else if(make.equals("Sony")) { 45 | 46 | //abstract factory pattern 47 | mobileStoreFactory = new SonySimpleFactory(mobileMechanic); 48 | } 49 | 50 | return mobileStoreFactory; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/singleton/threadsafe/MediaContractUsingThreadSafe.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.singleton.threadsafe; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class MediaContractUsingThreadSafe extends Thread { 31 | 32 | 33 | public void run() { 34 | getProductionHouse(); 35 | } 36 | 37 | public void getProductionHouse() { 38 | ProductionHouse productionHouse = ProductionHouse.getInstance(); 39 | System.out.println(productionHouse.toString()); 40 | } 41 | 42 | public static void main(String args[]) { 43 | 44 | demonstrate(); 45 | } 46 | 47 | public static void demonstrate() { 48 | 49 | MediaContractUsingThreadSafe thread01 = new MediaContractUsingThreadSafe(); 50 | thread01.start(); 51 | 52 | MediaContractUsingThreadSafe thread02 = new MediaContractUsingThreadSafe(); 53 | thread02.start(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/singleton/doublechecked/MediaContractUsingDoubleChecked.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.singleton.doublechecked; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class MediaContractUsingDoubleChecked extends Thread { 31 | 32 | 33 | public void run() { 34 | getProductionHouse(); 35 | } 36 | 37 | public void getProductionHouse() { 38 | ProductionHouse productionHouse = ProductionHouse.getInstance(); 39 | System.out.println(productionHouse.toString()); 40 | } 41 | 42 | public static void main(String args[]) { 43 | 44 | demonstrate(); 45 | } 46 | 47 | public static void demonstrate() { 48 | 49 | MediaContractUsingDoubleChecked thread01 = new MediaContractUsingDoubleChecked(); 50 | thread01.start(); 51 | 52 | MediaContractUsingDoubleChecked thread02 = new MediaContractUsingDoubleChecked(); 53 | thread02.start(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/decorator/PizzaWorld.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.decorator; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class PizzaWorld { 31 | 32 | public static void main(String args[]) { 33 | 34 | demonstrate(); 35 | } 36 | 37 | public static void demonstrate() { 38 | 39 | Pizza pizza = new Hawaiian("Veg Exotica"); 40 | pizza = new Mushroom(pizza); 41 | pizza = new Mushroom(pizza); 42 | pizza = new Onion(pizza); 43 | 44 | Pizza pizza1 = new Italian("Non-Veg Supreme"); 45 | pizza1 = new Chicken(pizza1); 46 | pizza1 = new Chicken(pizza1); 47 | pizza1 = new Onion(pizza1); 48 | pizza1 = new Onion(pizza1); 49 | 50 | System.out.println("Pizza World"); 51 | System.out.println("==========="); 52 | System.out.println(pizza.getDescription() + " " + pizza.cost()); 53 | System.out.println(pizza1.getDescription() + " " + pizza1.cost()); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/observer/StockData.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.observer; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * MIT License 8 | * 9 | * Copyright (c) 2018-19, Sumith Kumar Puri 10 | 11 | * GitHub URL https://github.com/sumithpuri 12 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 13 | * Blog Short URL https://goo.gl/kmSDiV 14 | * Package Prefix me.sumithpuri.github.phuket 15 | * Project Codename phuket 16 | * Contact E-Mail code@sumithpuri.me 17 | * Contact WhatsApp +91 9591497974 18 | * 19 | * 20 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 21 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 22 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 23 | * persons to whom the Software is furnished to do so, subject to the following conditions: 24 | * 25 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 26 | * Software. 27 | * 28 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 29 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 30 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 31 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | */ 33 | public class StockData implements Subject { 34 | 35 | private String stockSymbol = null; 36 | private Float stockValue = null; 37 | private Integer stockUnits = null; 38 | private List observers = null; 39 | 40 | public StockData() { 41 | observers = new ArrayList(); 42 | } 43 | 44 | @Override 45 | public void addObserver(Observer o) { 46 | observers.add(o); 47 | } 48 | 49 | @Override 50 | public void notifyObservers() { 51 | for (Observer o : observers) { 52 | o.update(stockSymbol, stockValue, stockUnits); 53 | } 54 | } 55 | 56 | @Override 57 | public void removeObserver(Observer o) { 58 | observers.remove(o); 59 | } 60 | 61 | public void setStockData(String stockSymbol, Float stockValue, Integer stockUnits) { 62 | // In real-time, this method might be invoked with values from a live web 63 | // service at regular intervals. 64 | this.stockSymbol = stockSymbol; 65 | this.stockValue = stockValue; 66 | this.stockUnits = stockUnits; 67 | setDataChanged(); 68 | } 69 | 70 | private void setDataChanged() { 71 | notifyObservers(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/method/MobileFactoryApp.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.method; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class MobileFactoryApp { 31 | 32 | //code demonstrates factory method - actually, multiple levels of factories 33 | //mobile store factory method is the demonstration of the factory method 34 | //nokia simple factory and sony simple factory are mobile story factory method implementations 35 | //nokia simple factory and sony simple factory are also simple factory(ies) themselves 36 | public static void main(String args[]) { 37 | 38 | demonstrate(); 39 | } 40 | 41 | public static void demonstrate() { 42 | 43 | //mobile store factory returns the factory as per the choice 44 | MobileStoreFactoryMethod storeFactory01 = MobileStoreFactory.getMobileFactory("Nokia"); 45 | Mobile mobile01 = storeFactory01.createMobile("ASeries"); 46 | 47 | System.out.println(mobile01.getMobileMake() + " " + mobile01.getMobileSeries() + " is Assembled/Created."); 48 | 49 | //mobile store factory returns the factory as per the choice 50 | MobileStoreFactoryMethod storeFactory02 = MobileStoreFactory.getMobileFactory("Sony"); 51 | Mobile mobile02 = storeFactory02.createMobile("BSeries"); 52 | 53 | System.out.println(mobile02.getMobileMake() + " " + mobile02.getMobileSeries() + " is Assembled/Created."); 54 | } 55 | } -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/factory/abstract_/MobileAbstractFactoryApp.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.factory.abstract_; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright (c) 2018-19, Sumith Kumar Puri 7 | 8 | * GitHub URL https://github.com/sumithpuri 9 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 10 | * Blog Short URL https://goo.gl/kmSDiV 11 | * Package Prefix me.sumithpuri.github.phuket 12 | * Project Codename phuket 13 | * Contact E-Mail code@sumithpuri.me 14 | * Contact WhatsApp +91 9591497974 15 | * 16 | * 17 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 18 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 19 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 20 | * persons to whom the Software is furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 23 | * Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 26 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 27 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 28 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 | */ 30 | public class MobileAbstractFactoryApp { 31 | 32 | //code demonstrates the abstract factory design pattern (also factory method and simple factory) 33 | //code also demonstrates factory method - actually, multiple levels of factories 34 | //mobile store factory method is the demonstration of the factory method 35 | //nokia simple factory and sony simple factory are mobile story factory method implementations 36 | //nokia simple factory and sony simple factory are also simple factory(ies) themselves 37 | public static void main(String args[]) { 38 | 39 | demonstrate(); 40 | } 41 | 42 | public static void demonstrate() { 43 | 44 | //let us first instantiate the absract factory implementation of our choice 45 | MobileStoreAbstractFactory abstractStoreFactory01 = new RobotMechanicStoreFactory(); 46 | //next is the factory method implementation of our choice, we choose nokia 47 | //this is a factory method implementation 48 | MobileStoreFactoryMethod storeFactory01 = abstractStoreFactory01.getMobileFactory("Nokia"); 49 | //now this is the simple factory implementation to retrieve the actual mobile 50 | Mobile mobile01 = storeFactory01.createMobile("ASeries"); 51 | 52 | System.out.println(mobile01.getMobileMake() + " " + mobile01.getMobileSeries() + " is Assembled/Created."); 53 | 54 | 55 | //let us first instantiate the absract factory implementation of our choice 56 | MobileStoreAbstractFactory abstractStoreFactory02 = new CertifiedMechanicStoreFactory(); 57 | //next is the factory method implementation of our choice, we choose nokia 58 | //this is a factory method implementation 59 | MobileStoreFactoryMethod storeFactory02 = abstractStoreFactory02.getMobileFactory("Sony"); 60 | //now this is the simple factory implementation to retrieve the actual mobile 61 | Mobile mobile02 = storeFactory02.createMobile("CSeries"); 62 | 63 | System.out.println(mobile02.getMobileMake() + " " + mobile02.getMobileSeries() + " is Assembled/Created."); 64 | 65 | 66 | } 67 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Phuket (Gang of Four Design Patterns) 2 | Code Samples for the Blog Article [Design Patterns - Series I] 3 |
4 | MIT License, Copyright (c) 2018-19, Sumith Kumar Puri
5 | https://github.com/sumithpuri 6 |
7 | 8 |

9 | 10 |

11 | 12 |
13 | 14 | 15 |
16 | 17 | |Project Codename|Phuket| 18 | |--|--| 19 | | Blog Post URL | http://www.techilashots.com/2008/11/design-patterns-series-i.html | 20 | |Blog Short URL |https://goo.gl/kmSDiV | 21 | |Package Prefix|me.sumithpuri.github.phuket | 22 | |GitHub URL|https://github.com/sumithpuri/skp-code-marathon-phuket | 23 | |Contact E-Mail |code@sumithpuri.xyz| 24 | |Contact Number|+91 9591497974 (WhatsApp, Viber, Telegram)| 25 | |Historical|✅ Started this Movement of 1000s of Lines of Java/EE* Code to GitHub
✅ Was a Senior Software Architect (Java/EE) in Manila*, 2018 (At Start) 
✅ Named this Initial Code Journey as [ Manila Code Marathon - 2018 ]
✅ Code Is Non-Proprietary / Non-Copyright from my Work Experience.
✅ Was Back to Bangalore, Named as [ Bangalore Code Nights - 2019. ]
✅ Added More Code under [ -20 Days of Code in Benglauru- ] in 2020
✅ Celebration of Java/Java EE Code as Java Turned 25 in the Year 2020! | 26 | 27 | 28 |
29 | 30 |
31 | 32 |
33 | 34 | 35 | 36 | 37 | 39 |

❤️ Ex-Yahoo, Symantec, Huawei, Oracle*, OpenText*, Finastra*, Atos*
🧡 Xth, XIIth (Computer Science) - Naval Public School, Kochi, India
💛 Bachelor of Engineering (Computer Science)* - SRSIT, Bangalore
💜 Executive Program ( Data Mining and Analytics ) - [IIT, Roorkee]
💚 Executive Certificate Program (Entrepreneurship) - IIM, Kashipur


💙 Proficience (Cryptography & Network Security) - IISc, Bangalore
🤎 Proficience (Innovative Product Design & Dev.) - IISc, Bangalore
🖤 Proficience (Artficial Intelligence/Intelli Agents) - IISc, Bangalore


💎 Sun Certified Java Programmer 1.4 (Core Java)
💎 Sun Certified Java Programmer 5.0 (Core Java)
💎 Sun Certified Business Component Developer 1.3 (EJB/J2EE)
💎 Sun Certified Business Component Developer 5.0 (EJB/J2EE)
💎 Brainbench Spring 2.x Certification*, ( J2EE/Spring )
💎 Brainbench Hibernate 3.x Certification* (Hibernate)
💎 Brainbench Java EE 6.x Certification*, ( J2EE )
💎 Quest C Lang. Certification (C Programming)
💎 Quest C++ Certification (C++ Programming)
💎 Quest Data Structures Certification ( C/C++ )


38 | 🏁 Highest IQ (147) ~ Among Entire Secondary School Batch ~ (Xth)
🏁 MVIT Inter-Collegiate C Programming Contest (Finalist, Top 8)
🏁 SJCIT Inter-Collegiate Web Design (Runners-Up)
🏁 Google India Code Jam 2005 (#376/14,000) - India + SE Asia
🏁 Microsoft Bizspark Startup 2011-'12 (Shortlisted/Recognized)
🏁 Societe Generale Brainwaves Hackathon 2015 (Corp Finalist, AI)
🏁 Mphasis Internal Hackathon Challenge, Season-07 (#07/106)*
🏁 Techgig Code Gladiators 2015 (Open, Top 500)
🏁 Accenture in India YouTube Contest 2015 (BigData, Winner)
🏁 Xebia-Microsoft-GitHub Blogathon 2022 (Microservices, Winner)


🏆 Senior Member, ACM (Elevated) and Senior Member, IEEE (Elevated)
🏆 Author/Blogger, Technology Advice (Developer.com and jGuru)
🏆 DZone Most Valuable Blogger and DZone Core (Elevated)**
🏆 Author and Blogger, Friends of Open JDK Community (Foojay.IO)
🏆 Blogger, Java Code Geeks Program (Shortlisted/Recognized)
🏆 Paid Blogger, Developer.com and jGuru; Blogger, HackerNoon;
🎯 19y Across Associate/Engineer (2003) to Java Practice Leader (2024)

40 | 41 |
42 | 43 |
44 |
45 |
🔴 ALL COPYRIGHTS FOR THE ABOVE PUBLICLY AVAILABLE IMAGE OR PARTS OF THE IMAGE ARE WITH THEIR RESPECTIVE OWNERS, SOURCED/USED FROM GOOGLE SEARCH
46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/phuket/main/gof_Phuket.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.phuket.main; 2 | 3 | import me.sumithpuri.github.phuket.command.AuctionStore; 4 | import me.sumithpuri.github.phuket.decorator.PizzaWorld; 5 | import me.sumithpuri.github.phuket.observer.StockBroker; 6 | import me.sumithpuri.github.phuket.singleton.doublechecked.MediaContractUsingDoubleChecked; 7 | import me.sumithpuri.github.phuket.singleton.eager.MediaContractUsingEager; 8 | import me.sumithpuri.github.phuket.singleton.threadsafe.MediaContractUsingThreadSafe; 9 | 10 | /** 11 | * MIT License 12 | * 13 | * Copyright (c) 2018-19, Sumith Kumar Puri 14 | 15 | * GitHub URL https://github.com/sumithpuri 16 | * Blog Post URL http://www.techilashots.com/2008/11/design-patterns-series-i.html 17 | * Blog Short URL https://goo.gl/kmSDiV 18 | * Package Prefix me.sumithpuri.github.phuket 19 | * Project Codename phuket 20 | * Contact E-Mail code@sumithpuri.me 21 | * Contact WhatsApp +91 9591497974 22 | * 23 | * 24 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 25 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 26 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 27 | * persons to whom the Software is furnished to do so, subject to the following conditions: 28 | * 29 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 30 | * Software. 31 | * 32 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 33 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 34 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 35 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 36 | */ 37 | 38 | /* 39 | * You may run this main class to run all the Demo Code of the [Phuket] Project. It demonstrates five of most important 40 | * Gang of Four (GoF) Design Patterns using Core Java. 41 | */ 42 | public class gof_Phuket { 43 | 44 | public static void main(String[] args) throws Exception { 45 | 46 | System.out.println("Copyright (c) 2018-19, Sumith Kumar Puri"); 47 | System.out.println(); 48 | System.out.println("Project Codename Phuket"); 49 | System.out.println("Project Description GoF Design Patterns Companion Code Samples (01/02)"); 50 | System.out.println("Technical Blog http://www.techilashots.com"); 51 | System.out.println("Technical Blog Post https://goo.gl/kmSDiV"); 52 | System.out.println("[Developer Notes] [01] Use Java Version 9.0+ Compiler"); 53 | 54 | System.out.println(); 55 | System.out.println("------------------------------------------------------------"); 56 | System.out.println("[01. Observer Design Pattern (GoF)]"); 57 | observer(); 58 | System.out.println("------------------------------------------------------------"); 59 | System.out.println("[02. Decorator Design Pattern (GoF)]"); 60 | decorator(); 61 | System.out.println("------------------------------------------------------------"); 62 | System.out.println("[3a. Singleton Design Pattern (GoF) - Eager Implementation]"); 63 | eagerSingleton(); 64 | Thread.sleep(100); 65 | System.out.println("------------------------------------------------------------"); 66 | System.out.println("[3b. Singleton Design Pattern (GoF) - Thread Safe Implementation]"); 67 | threadSafeSingleton(); 68 | Thread.sleep(100); 69 | System.out.println("------------------------------------------------------------"); 70 | System.out.println("[3c. Singleton Design Pattern (GoF) - Double Checked Locking Implementation]"); 71 | doubleCheckedLockingSingleton(); 72 | Thread.sleep(100); 73 | System.out.println("------------------------------------------------------------"); 74 | System.out.println("[04. Command Design Pattern (GoF)]"); 75 | command(); 76 | System.out.println("------------------------------------------------------------"); 77 | System.out.println("[5a. Factory Design Pattern (GoF) - Simple Factory Implementation]"); 78 | simpleFactory(); 79 | System.out.println("------------------------------------------------------------"); 80 | System.out.println("[5b. Factory Design Pattern (GoF) - Factory Method Implementation]"); 81 | factoryMethod(); 82 | System.out.println("------------------------------------------------------------"); 83 | System.out.println("[5c. Factory Design Pattern (GoF) - Abstract Factory Implementation]"); 84 | abstractFactory(); 85 | System.out.println("------------------------------------------------------------"); 86 | System.out.println("[Note: Refer Provided Code, Run One-By-One to Understand Thoroughly!]"); 87 | System.out.println(); 88 | } 89 | 90 | 91 | private static void observer() { 92 | 93 | StockBroker stockBroker = new StockBroker(); 94 | stockBroker.demonstrate(); 95 | } 96 | 97 | private static void decorator() { 98 | 99 | PizzaWorld pizzaWorld = new PizzaWorld(); 100 | pizzaWorld.demonstrate(); 101 | } 102 | 103 | private static void command() { 104 | 105 | AuctionStore auctionStore = new AuctionStore(); 106 | auctionStore.demonstrate(); 107 | } 108 | 109 | private static void eagerSingleton() { 110 | 111 | MediaContractUsingEager mediaContract = new MediaContractUsingEager(); 112 | mediaContract.demonstrate(); 113 | } 114 | 115 | private static void threadSafeSingleton() { 116 | 117 | MediaContractUsingThreadSafe mediaContract = new MediaContractUsingThreadSafe(); 118 | mediaContract.demonstrate(); 119 | } 120 | 121 | private static void doubleCheckedLockingSingleton() { 122 | 123 | MediaContractUsingDoubleChecked mediaContract = new MediaContractUsingDoubleChecked(); 124 | mediaContract.demonstrate(); 125 | } 126 | 127 | private static void simpleFactory() { 128 | 129 | StockBroker stockBroker = new StockBroker(); 130 | stockBroker.demonstrate(); 131 | } 132 | 133 | private static void factoryMethod() { 134 | 135 | StockBroker stockBroker = new StockBroker(); 136 | stockBroker.demonstrate(); 137 | } 138 | 139 | private static void abstractFactory() { 140 | 141 | StockBroker stockBroker = new StockBroker(); 142 | stockBroker.demonstrate(); 143 | } 144 | } 145 | --------------------------------------------------------------------------------