Using the UML Drawing Tool by implementing the code in Java demonstrate the Expert
1.Design Pattern.
An Expert pattern is useful in maintaining encapsulation
of information, it promotes low coupling and also provides highly cohesive
classes which can cause a class to become excessively complex.
Code Implementation:
Product Description.java:
import java.io.*;
public class ProductDescription
{
private float price=43.89f;
public float getPrice ()
{
return price;
}
}
SalesCounter.java:
import java.io.*;
public class SaleCounter
{
public static
void main (String [] args)
{
float total;
Sales s=new Sales();
total=s.getTotal();
System.out.println ("Total sale is:
"+total);
}
}
Sales .java:
import java.io.*;
public class Sales
{
private float
total;
public float
getTotal()
{
ProductDescription
pd=new ProductDescription ();
SalesLineItem
sli=new SalesLineItem ();
total=(pd.getPrice()*sli.getSubTotal());
return
total;
}
}
SalesLineItem:
public class SalesLineItem
{
private int quantity=100;
public int getSubTotal()
{
return
quantity;
}
}
No comments:
Post a Comment