/**
* Return radius value
* @return
*/
Public double Getradius ();
/**
* Set RADIUS value
* @param radius
*/
public void Setradius (double radius);
}
Package cn.edu.ynu.sei.adapter;
/**
* Square Type <br>
* This is the source role of the object's adapter pattern
*
* @author 88250
* @version 1.0.0, 2007-8-28
*/
public class Cube
{
private double width;
/**
* Calculated surface Area
* @return
*/
Public double Calculatefacearea ()
{
Return 6 * Width * width;
}
/**
* @return The width
*/
Public double getwidth ()
{
return width;
}
/**
* @param width of the width to set
*/
public void SetWidth (double width)
{
this. width = width;
}
}
Package cn.edu.ynu.sei.adapter;
/**
* This class acts as a "finger-round" adapter role
*
* @author 88250
* @version 1.0.0, 2007-8-28
*/
public class Magicfinger implements BALLF
{
private double radius;
Private static final Double PI = 3.1415926D;
Private Cube adaptee;
Public Magicfinger (Cube adaptee)
{
Super ();
this. Adaptee = Adaptee;
Radius = Adaptee.getwidth ();
}
@Override
Public double CalculateArea ()
{
return PI * 4.0D * (RADIUS * radius);
}
@Override
Public double Calculatevolume ()
{
Return PI * (4.0d/3.0d) * (RADIUS * radius * radius);
}
@Override
Public double Getradius ()
{
return radius;
}
3. SummaryThe above implementation is the object's adapter pattern, that is, the source role is a class. If the source role is an interface, then the adapter mode for the class, which is no longer repeat here.
The JDBC that we often use is the specific application of an adapter pattern, and the wine simulator (which can simulate Windows) under Linux is also the application of adapter mode.
4. Reference Documents"Design Patterns", "Java and Mode"
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