Java design mode-multi-Factory mode

Source: Internet
Author: User

ConceptMultiple factory models are an improvement to the common factory approach, where, in normal Factory mode, objects are not created correctly if there is an error in string delivery, and multiple factory modes provide multiple factory methods to create the objects individually.multiple Factory mode diagramsMultiple Factory mode We only need to refer to (http://www.cnblogs.com/MrMedici/p/7895248.html) Snedfactory This class to modify the line, as follows: Multiple factory modes are created as follows: public class sendfactory {Mail Send Factory mode public sender Producemail () {return new MailSender (); Mail Sender Factory mode public Sender Producesms () {retur N New Smssender ();}} The test class is as follows: [Java] View Plaincopypublic class Factorytest {public static void main (string[] args) {Sendfactory factory = new Se Ndfactory (); Sender sender = Factory.producemail (); sender. Send (); }} Output: This is mailsender!

Java design mode-multi-Factory mode

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.