Java Factory mode Factory

Source: Internet
Author: User

Factory mode:

1) We first need to design the car car needs those processes (face)

 PackageLight.zhang.model.model.facotry;/*** Car building process, defined process *@authorWitts **/ Public InterfaceIcarface {/*** Draw Pictures*/    voidDrawImage (); /*** Design Model*/    voidCreatemodel (); /*** Achieve production*/    voidImplcar (); /*** Test the car*/    voidTestcar ();}

2. Automotive Manufacturers (Implementation)

 PackageLight.zhang.model.model.facotry;/*** Odison Manufacturers *@authorWitts **/ Public classAodicompanyImplementsIcarface {@Override Public voidDrawImage () {System.out.println ("Audi Company-image Model"); } @Override Public voidCreatemodel () {System.out.println ("Audi Company-Create Model"); } @Override Public voidImplcar () {System.out.println ("Audi Company-production Body"); } @Override Public voidTestcar () {System.out.println ("Audi Company-Test Body"); }         }

Package light.zhang.model.model.facotry;

/**
* BMW Corporation
* @author Witts
*/
public class Bmwcompany implements Icarface {
@Override
public void DrawImage () {
System.out.println ("BMW Company-image model");
}

@Override
public void Createmodel () {
System.out.println ("BMW company-Create model");
}

@Override
public void Implcar () {
System.out.println ("BMW Company-production bodywork");
}

@Override
public void Testcar () {
System.out.println ("BMW Company-Test Body");
}

}

3) 4S Shop now to organize Audi BMW car, 4S Shop is a factory, he is responsible for the Audi BMW's car finishing, the user to buy a car only need to tell the salesman I want to buy what car

 PackageLight.zhang.model.model.facotry;/*** 4S shop start to sell those cars? * @authorWitts **/ Public classCar4sdianfactory { PublicIcarface Getcar (inttype) {         if(Type = = 1) {             return NewAodicompany (); }         if(Type = = 2) {             return NewBmwcompany (); }         return NULL; }}

4) The user starts to buy a car (call)

 PackageLight.zhang.model.model.facotry;/*** Users start to go to the 4S shop to buy a car *@authorWitts **/ Public classUsershoppingcar { Public Static voidMain (string[] args) {Car4sdianfactory factory=Newcar4sdianfactory (); Icarface Aodicar=factory.getcar (1);//Audi Company's carAodicar.testcar (); Icarface Bmwcar= Factory.getcar (2);//BMW Company's carBmwcar.testcar (); }}

Java Factory mode Factory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.