Factory model

Creation logic is not exposed to users , And by using a common interface to point to the newly created object .
Take the simple factory as an example
// Provide a unified abstract interface for subclass implementation public interface Factory { void create(); } // Subclasses implement abstract interfaces
public class Computer implements Factory{ @Override public void create() {
System.out.println("I am Computer Product ! Create an Computer"); } } public
class Car implements Factory{ @Override public void create() {
System.out.println("I am Car Product ! Create a car"); } } // Real factory approach , Provide examples as required
public class RealFactory { public Factory getFactory (String want) { if (want ==
null || "".equals(want)) { return null; } if (want.equals("car")) { return new
Car(); }else if (want.equals("computer")) { return new Computer(); } else {
return null; } } } // Examples of use public class FactoryDemo { public static void main
(String[] args) {/** * Define an interface for creating objects , Let subclasses decide which class to instantiate .Factory Method
Delay the instantiation of a class to its subclasses . */ RealFactory factory = new RealFactory(); Factory carFactory
= factory.getFactory("car"); carFactory.create(); Factory computerFactory =
factory.getFactory("computer"); computerFactory.create(); } }
Android Factory model in

Excellent implementation

Middle tier for using multiple third parties , Call the real implementation according to the configuration

©2019-2020 Toolsou All rights reserved,
Forbes China Auto rich list : He xiaopengdi 11 Li Xiangdi 14 Li Bindi 15 Change one's mind ! Tesla starts to deliver made in China to European market Model 3 The difference between memory overflow and memory leak , Causes and Solutions Character recognition technology of vehicle license plate based on Neural Network Vue Transfer parameters and receiving of page Jump SparkSQL Achieve partition overlay write 1190 Reverses the substring between each pair of parentheses leetcode Note 14 : The second biggest obstacle to motivating others in R & D management Chrome OS, For programmers and Windows What does it mean ? Internet Marketing JAVA Convert a string to a numeric type