Design pattern learning notes

xiaoxiao2021-03-06  56

2004-11-10 Wednesday

1. What is design mode? A: 1) Design mode is a reuse solution; 2) Design mode builds a series of rules description how to complete the appropriate tasks in software development, one mode is positioned in a specific design environment. Reuters can reuse design problems and provide a solution;

2. Factory mode A:

public class CarCreateDemo {public static void main (String [] args) {CarCreate carCreate = new CarCreate (); AudiType audiType = new AudiType (); BWMType bwmType = new BWMType (); BenzType benzType = new BenzType (); carCreate.createCar (Auditype); carcreate.createcar (bwmtype); carcreate.createcar (benzType);}}

Class carcreate {public void createcar (iCARTYPE CARTYPE) {Icar Car = Cartype.createcar (); car.createWheel (); car.createEngine (); car.createengine (); car.createdoor ();}}

Interface iCARTYPE {Icar createcar ();

Class Auditype Implements Icartype {Public Icar CreateCar () {Return New Audi ();}}

Class BWMTYPE IMPLEMENTS ICARTYPE {public iCar Createcar () {Return New BWM ();}}

Class BenzType Implements Icartype {Public Icar Createcar () {Return New Benz ();}}

Interface iCar {void CreateEel (); void createngine (); void createDoor ();

class Audi implements ICar {public void createWheel () {System.out.println ( "Create Audi Wheel");} public void createEngine () {System.out.println ( "Create Audi Engine");} public void createDoor () {System.out.println ("CREATE AUDI DOOR");}};

class BWM implements ICar {public void createWheel () {System.out.println ( "Create BWM Wheel");} public void createEngine () {System.out.println ( "Create BWM Engine");} public void createDoor () {System.out.Println ("Create Bwm Door");}};

class Benz implements ICar {public void createWheel () {System.out.println ( "Create Benz Wheel");} public void createEngine () {System.out.println ( "Create Benz Engine");} public void createDoor () . {System.out.println ( "Create Benz Door");}}; 3 Singleton model A: public class ProductLineDemo {public static void main (String [] args) {ProductLine productLine1 = ProductLine.getProductLine (); ProductLine productLine2 = ProductLine.GetProductLine (); productLine1.createProduct (); productLine2.createProduct ();}};

Class Productline Extends Thread {static productLine instance = null; int number = 0; int maxProduct = 10;

PRIVATE PRODUCTLINE ()}; public static productLine getProductLine () {if (instance == null) {instance = new productLine ();} Return Instance;

public void createProduct () {if (numberOfProduct

转载请注明原文地址:https://www.9cbs.com/read-90869.html

New Post(0)