标签:@param 工厂方法 使用 equal 说明 ilo and form blog
package cn.sun.code.one.ouhe;
/**
* Created by rider on 2018/11/21.
* 1.9 紧耦合 vs 松耦合
*/
public class Operation {
private double numberA;
private double numberB;
public double getNumberA() {
return numberA;
}
public void setNumberA(double numberA) {
this.numberA = numberA;
}
public double getNumberB() {
return numberB;
}
public void setNumberB(double numberB) {
this.numberB = numberB;
}
public double getResult() {
double result = 0d;
return result;
}
}
class OperationAdd extends Operation {
public double getResult() {
double result = 0d;
result = this.getNumberA() + this.getNumberB();
return result;
}
}
class OperationSub extends Operation {
public double getResult() {
double result = 0d;
result = this.getNumberA() - this.getNumberB();
return result;
}
}
class OperationMul extends Operation {
public double getResult() {
double result = 0d;
result = this.getNumberA() * this.getNumberB();
return result;
}
}
class OperationDiv extends Operation {
public double getResult() {
double result = 0d;
if(getNumberB()==0)
throw new RuntimeException("除数不能为0");
result = this.getNumberA() / this.getNumberB();
return result;
}
}
package cn.sun.code.one.ouhe;
/**
* Created by rider on 2018/11/21.
* 简单工厂模式
*/
public class OperationFactory {
public static Operation createOperate(String operate) {
Operation operation = null;
switch (operate) {
case "+":
operation = new OperationAdd();
break;
case "-":
operation = new OperationSub();
break;
case "*":
operation = new OperationMul();
break;
case "/":
operation = new OperationDiv();
break;
}
return operation;
}
/**
* 客户端代码
*
* @param args
*/
public static void main(String[] args) {
Operation operation = null;
operation = OperationFactory.createOperate("+");
operation.setNumberA(1);
operation.setNumberB(2);
double result = operation.getResult();
System.out.println(result);
}
}
public static Calendar getInstance(Locale aLocale)
{
return createCalendar(TimeZone.getDefault(), aLocale);
}
private static Calendar createCalendar(TimeZone zone,
Locale aLocale)
{
CalendarProvider provider =
LocaleProviderAdapter.getAdapter(CalendarProvider.class, aLocale)
.getCalendarProvider();
if (provider != null) {
try {
return provider.getInstance(zone, aLocale);
} catch (IllegalArgumentException iae) {
// fall back to the default instantiation
}
}
Calendar cal = null;
if (aLocale.hasExtensions()) {
String caltype = aLocale.getUnicodeLocaleType("ca");
if (caltype != null) {
switch (caltype) {
case "buddhist":
cal = new BuddhistCalendar(zone, aLocale);
break;
case "japanese":
cal = new JapaneseImperialCalendar(zone, aLocale);
break;
case "gregory":
cal = new GregorianCalendar(zone, aLocale);
break;
}
}
}
if (cal == null) {
// If no known calendar type is explicitly specified,
// perform the traditional way to create a Calendar:
// create a BuddhistCalendar for th_TH locale,
// a JapaneseImperialCalendar for ja_JP_JP locale, or
// a GregorianCalendar for any other locales.
// NOTE: The language, country and variant strings are interned.
if (aLocale.getLanguage() == "th" && aLocale.getCountry() == "TH") {
cal = new BuddhistCalendar(zone, aLocale);
} else if (aLocale.getVariant() == "JP" && aLocale.getLanguage() == "ja"
&& aLocale.getCountry() == "JP") {
cal = new JapaneseImperialCalendar(zone, aLocale);
} else {
cal = new GregorianCalendar(zone, aLocale);
}
}
return cal;
}
public static Logger getLogger(String name) {
ILoggerFactory iLoggerFactory = getILoggerFactory();
return iLoggerFactory.getLogger(name);
}
{
Logger slf4jLogger = (Logger)this.loggerMap.get(name);
if (slf4jLogger != null) {
return slf4jLogger;
} else {
org.apache.log4j.Logger log4jLogger;
if (name.equalsIgnoreCase("ROOT")) {
log4jLogger = LogManager.getRootLogger();
} else {
log4jLogger = LogManager.getLogger(name);
}
Logger newInstance = new Log4jLoggerAdapter(log4jLogger);
Logger oldInstance = (Logger)this.loggerMap.putIfAbsent(name, newInstance);
return (Logger)(oldInstance == null ? newInstance : oldInstance);
}
}
标签:@param 工厂方法 使用 equal 说明 ilo and form blog
原文地址:https://www.cnblogs.com/riders/p/12191235.html