Java?м????????????
???????????? ???????[ 2017/6/20 10:32:41 ] ??????????????????? Java
????1.?????????е???????е??????????????
?????????????????????б???1????????????????????
????package org.sp.singleton;
????//?????
????public class Singleton {
????//?????????????????????????????????Static??final???η?
????private static final Singleton instance = new Singleton();
????//???????????ó???????
????private Singleton() {
????}
????//?????????????????????????????
????public static Singleton getInstance() {
????return instance;
????}
????}
????//??????
????class Singleton2 {
????private static Singleton2 instance2 = null;
????public static synchronized Singleton2 getInstance() {
????if (instance2 == null)
????instance2 = new Singleton2();
????return instance2;
????}
????}
????????????????????????????????????????????????????
????2.??????
????????????????????????????????á?????????????
????public class Factory{
????public ClassesDao getClassesDao(){
????ClassesDao cd = new ClassesDaoImpl();
????return cd;
????}
????}
????interface ClassesDao{
????public String getClassesName();
????}
????class ClassesDaoImpl implements ClassesDao {
????public String getClassesName(){
????System.out.println("A??");
????}
????}
????class test
????{
????public static void main(String[] args){
????Factory f = new Factory();
????f.getClassesDao().getClassesName();
????}
????}
??????????????????????????????????????????????????
????3.??????
???????????????????????????????к?????????????????????????????????????????????к????????????Щ????????????????????????????Щ????????????????????????á??????Щ?????????????y???????
????4.??????
?????????????о?????Service?????????檔????Dao???????????????????????????Service??Dao????????????????????????????????????????????????????????????
???????忴??????????
????interface ClassesDao{
????public String getClassesName();
????}
????class ClassesDaoImpl implements ClassesDao {
????public String getClassesName(){
????return "A??";
????}
????}
????interface ClassesDao2{
????public String getClassesName();
????}
????class ClassesDaoImpl2 implements ClassesDao {
????public String getClasses2Name(){
????return "B??";
????}
????}
????class ServiceManager
????{
????private ClassesDao cd = new ClassesDaoImpl();
????private ClassesDao2 cd2 = new ClassesDaoImpl2();
????public void printOut(){
????System.out.println(cd.getClassesName()+" "+cd2.getClassesName());
????}
????};
???????????????????????????????????????
????5.??????
?????????????????????????м??????????????????????????????????????????????????????
??????????????
????package org.sp.strategy;
????/**
????* ????????????
????* @author ???de??????
????*
????*/
????public class Addition extends Operation {
????@Override
????public float parameter(float a?? float b) {
????return a+b;
????}
????}
????package org.sp.strategy;
????/**
????* ?????????????
????* @author ???de??????
????*
????*/
????public class Division extends Operation {
????@Override
????public float parameter(float a?? float b) {
????return a/b;
????}
????}
????package org.sp.strategy;
????/**
????* ????????????
????* @author ???de??????
????*
????*/
????public class Multiplication extends Operation{
????@Override
????public float parameter(float a?? float b) {
????return a*b;
????}
????}
????package org.sp.strategy;
????/**
????* ?????????????
????* @author ???de??????
????*
????*/
????public class Subtration extends Operation {
????@Override
????public float parameter(float a?? float b) {
????return a-b;
????}
????}
????package org.sp.strategy;
????/**
????* ????????????????y????????
????* @author ???de??????
????*
????*/
????public abstract class Operation {
????public abstract float parameter(float a?? float b);
????}
????package org.sp.strategy;
????/**
????* ?????????
????* @author ???de??????
????*
????*/
????public class Condition {
????public static final Addition add = new Addition();
????public static final Subtration sub = new Subtration();
????public static final Multiplication mul = new Multiplication();
????public static final Division div = new Division();
????}
????package org.sp.strategy;
????/**
????* ????????
????* @author ???de??????
????*
????*/
????public class Client {
????public static void main(String[] args) {
????float a = 100;
????float b = 25;
????System.out.println(Condition.div.parameter(a?? b));
????}
????}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11