Java Best Practices 01 | Static Factory Methods Over Constructors

Static Factory Methods Consider using Static Factory Methods Instead of Constructors The static factory method is a method that returns an instance of the class. Example In this example, we will build some HTML elements using Java. Here is the base class. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 class HtmlElement { private final String tag; private final String content; public HtmlElement(String tag, String content) { this....

May 27, 2021 · Noor · Java Java

Solid Design Principles with Java – #01 Single Responsibility Principle (SRP)

Solid Design Principles with Java Series Welcome to this new series of solid design principles with Java programming language. In this series we will focus on the most important design principles, introduce them with minimal efforts on both us and the reader, this series should be followed by a more advanced one on design patterns with Java later on – stay tuned! Single Responsibility Principle (SRP) On this first lesson, we will discuss the Separation of Concerns (SoC) aka Single Responsibility Principle (SRP)....

March 30, 2019 · Noor · Java Java