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

Technology
©2019-2020 Toolsou All rights reserved,
【 Explain in detail 】 Interview must ask :SpringBoot Automatic configuration principle 【 Hyper detail 】Java Realization of student information management system 2020 The 11th National Blue Bridge Cup Python group JavaScript note ( five )---- Branch statement MYSQL database SQL Sentence practice experiment EXERCISES. 1 SIMPLE COMMANDSMySQL Basics Commonly used sentence ( Add / delete / modify query )C++ of string of compare usage vue limit input Only positive numbers can be entered C Language of a Gobang game implementation Programmer refused due to low salary offer,HR become shame , Netizens instantly blew up ..