Java Reference
In-Depth Information
You can now connect two processing objects to construct a chain of operations!
Using lambda expressions
Wait a minute! This pattern looks like chaining (that is, composing) functions! We discussed
how to compose lambda expressions in chapter 3 . You can represent the processing objects as
an instance of Function<String, String> or more precisely a UnaryOperator<String>. To chain
them you just need to compose these functions by using the andThen method!
8.2.5. Factory
The factory design pattern lets you create objects without exposing the instantiation logic to the
client. For example, let's say you're working for a bank and they need a way of creating different
financial products: loans, bonds, stocks, and so on.
Typically you'd create a Factory class with a method that's responsible for the creation of
different objects, as shown here:
public class ProductFactory {
public static Product createProduct(String name){
switch(name){
case "loan": return new Loan();
case "stock": return new Stock();
case "bond": return new Bond();
 
Search WWH ::




Custom Search