Java design patterns are commonly used in 21 kinds

Source: Internet
Author: User
java Design Patterns are commonly used in 21 kinds

1. Creative Type: Abstract Factory

[java]  View Plain  copy package com.seezoon. Create type. Abstract Factory;     /**   *   Abstract Factory    *  @author  DF   * Factory method Pattern One problem is that class creation relies on factory classes, that is, if you want to expand the program,   * The factory class must be modified, which violates the closure principle, therefore, from the design point of view, there are certain problems, how to solve.    * uses an abstract factory model to create multiple factory classes so that once you need to add new functionality, add new factory classes directly,   * No need to modify the previous code    */   public class abstractfactory {       public static void  main (String[] args)  {           ifactory  factory = new productafactory ();            iproduct product = factory.produce ();            product.productmethod ();       }  }   interface  IFactory {       PUBLIC IPRODUCT&NBSp;produce ();  }   class productafactory implements ifactory{        @Override        public iproduct produce ()   {           return new producta ();       }  }   class productbfactory implements ifactory{         @Override        public IProduct  Produce ()  {           RETURN NEW PRODUCTB ();        }  }   interface iproduct {        public void productmethod ();  }      class  producta implements iproduct {        @Override        &nBsp;public void productmethod ()  {            System.out.println ("ProductA");       }  

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.