filmov
tv
Static Factory Method
![preview_player](https://i.ytimg.com/vi/6pshPs01anU/maxresdefault.jpg)
Показать описание
From Joshua Bloch's "Effective Java", this is Item 01: Consider static factory methods instead of constructors
A static factory method is an alternative to creating objects without invoking constructors directly. This technique should not be confused with the Factory Pattern from the GoF.
The purpose of the static factory method is the same as a class constructor: to provide instances of a class. It differs from constructors in that a class can have several static factory methods with different names that indicate purpose.
Advantages:
1) Methods have descriptive names.
2) They are not require to provide new instances every time they are invoked.
3) Can return an object of any sub-type of their return type.
4) The class of the returned object can vary from call to call as a function of the input.
5) The class of the returned object need not exist when the class containing the method is written.
Limitations:
1) Classes without public or protected constructors cannot be sub-classed.
2) Factory methods are hard for programmers to find (vs Constructors which are easy to find).
A static factory method is an alternative to creating objects without invoking constructors directly. This technique should not be confused with the Factory Pattern from the GoF.
The purpose of the static factory method is the same as a class constructor: to provide instances of a class. It differs from constructors in that a class can have several static factory methods with different names that indicate purpose.
Advantages:
1) Methods have descriptive names.
2) They are not require to provide new instances every time they are invoked.
3) Can return an object of any sub-type of their return type.
4) The class of the returned object can vary from call to call as a function of the input.
5) The class of the returned object need not exist when the class containing the method is written.
Limitations:
1) Classes without public or protected constructors cannot be sub-classed.
2) Factory methods are hard for programmers to find (vs Constructors which are easy to find).
What are static factory methods in Java? - 036
Static Factory Methods - Effective Java, Item 1
What is Static Factory Method in Java? | Static Factory Method | Java Language
Static Factory Methods: Part 1 - Readability
Static Factory Method JAVA
Static Factory Methods in Java
Are Factory Methods Better Than Constructors?
The Factory Method Pattern Explained and Implemented in Java | Creational Design Patterns | Geekific
P3-Implementing DesignPatterns | Singleton Pattern | Factory and Service | Spring & Hibernate
Implement the Factory Method Design Pattern
Effective Java Book - Item-1 | Static Factory Method instead of constructors
Code Elegance: How to Level Up with Static Factory Methods (JavaScript Example)
Effective Java | Item 1 Consider static factory methods instead of constructors
Singleton Class | Static Factory Method | Java
Static Factory Method - Devsena Mishra
Static Factory Methods vs Constructor (Static Factory Wins!)
Constructor vs Static factory methods
Factory Design Pattern in Java Explained in 3 Minutes
Static Factory Method
System Design LLD : Static factory method to create Objects (Java) (Object Creation Part-1)
Factory Pattern in C#: Creating Objects with Ease
Java :What are static factory methods?(5solution)
Factory Design Pattern in Java Theory
Static Factory Method, czyli jak tworzyć obiekty
Комментарии