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,
use css Design a simple style html login interface The industrial Internet may not be 5G My life-saving straw C/C++ Memory model Do you have a magic interview ? Half a month 25 College questions , Actually captured Ali P8offerJava Misunderstanding —— Method overloading is a manifestation of polymorphism ?springboot2 Separation of front and rear platforms ,token Put in header Pit for verification Regression of dependent variable order categories (R language )Pandas Fundamentals of statistical analysis _ data processing (DataFrame Common operations )Unity2019 UIElement note ( ten ) Simple exercise 2 45 The 12-year-old programmer was turned down , Is the workplace wrong ?