Java implementation of Builder (BUilder) model [00 original]__java
Source: Internet
Author: User
The following examples come from Java and schema.
Suppose there is a system of electronic magazines built in Java that regularly sends electronic magazines to users ' email mailboxes. Users can subscribe through a Web page, or they can end subscriptions through a Web page. When a customer starts a subscription, the system sends an e-mail to welcome it, and when the customer ends the subscription, the system sends an e-mail message saying goodbye. This example is the module that the system is responsible for sending "welcome" and "send-off" messages.
1. Class Diagram
Create a Message Object
message = new MimeMessage (session);
Building a sender's address part
Message.setfrom (New InternetAddress (from));
Building Theme Parts
Message.setsubject ("Hello from Jeff");
Build Send Time part
Message.setsentdate (senddate);
Building Content Parts
Message.settext ("Hello, how are things going?");
Send a message, equivalent to a product reception method
Transport.send (message);
System.out.println ("Email has been sent.");
}
catch (Exception e)
{
E.printstacktrace ();
}
}
/**
* @return The subject
*/
Public String Getsubject ()
{
return subject;
}
/**
* @param subject the subject to set
*/
public void Setsubject (String subject)
{
this. Subject = subject;
}
/**
* @return The body
*/
Public String GetBody ()
{
return to body;
}
/**
* @param body to set
*/
public void Setbody (String body)
{
this. Body = body;
}
/**
* @return the From
*/
Public String Getfrom ()
{
return from;
}
/**
* @param from-to set
*/
public void Setfrom (String from)
{
this. From = from;
}
/**
* @return The Senddate
*/
Public Date getsenddate ()
{
return senddate;
}
/**
* @param senddate the senddate to set
*/
public void Setsenddate (Date senddate)
{
this. senddate = Senddate;
}
/**
* @return The To
*/
Public String Getto ()
{
return to;
}
/**
* @param to the To set
*/
public void Setto (String to)
{
this. to = to;
}
}
/**
* Theme Parts Construction method
*/
public abstract void Buildsubject ();
/**
* Content Part Construction method
*/
public abstract void Buildbody ();
/**
* Sender Part Construction method
* @param from
*/
public void Buildfrom (String from)
{
Msg.setfrom (from);
}
/**
* Recipient Part Construction method
* @param to
*/
public void Buildto (String to)
{
System.out.println (to);
Msg.setto (to);
}
/**
* Send Time Part construction method
*/
public void Buildsenddate ()
{
Msg.setsenddate (New Date ());
}
/**
* Send mail with this method when the mail product is finished <br>
* This method is equivalent to the product return method
*/
public void SendMessage ()
{
Msg.send ();
}
}
Package cn.edu.ynu.sei.builder;
/**
* Mail Sending system customer
*
* @author 88250
* @version 1.0.0, 2007-8-24
*/
public class Client
{
private static Builder Builder;
private static Director Director;
public static void Main (string[] args)
{
Builder = new Welcomebuilder ();
Director = new Director (builder);
Director.construct ("jeffyan77@yahoo.com", "javapatterns@yahoo.com");
}
}
Package cn.edu.ynu.sei.builder;
/**
* Director Role
*
* @author 88250
* @version 1.0.0, 2007-8-24
*/
public class Director
{
Builder Builder;
Public Director (Builder Builder)
{
this. Builder = Builder;
}
/**
* Product Construction method, responsible for the call of the parts construction method
* @param toaddress
* @param fromaddress
<
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.