当前位置: 首页 > news >正文

临沭做网站seo思维

临沭做网站,seo思维,wordpress批量发邮,优化门户网站建设面向对象的七大原则(OOP) 1,开闭原则: 对扩展开发,对修改关闭 2.里氏替换原则: 继承必须确保超类所拥有的子类的性质在子类中仍然成立 3.依赖倒置原则: 面向接口编程,不要面向实现编程&am…

面向对象的七大原则(OOP)

1,开闭原则:

对扩展开发,对修改关闭

2.里氏替换原则:

继承必须确保超类所拥有的子类的性质在子类中仍然成立

3.依赖倒置原则:

面向接口编程,不要面向实现编程,降低程序之间的耦合性

4.单一职责原则:

控制类的粒度大小,将对象解耦,提高其内聚性

5.接口隔离原则:

要为各个类创建他们专用的接口

6.迪米特法则:

只于你的直接朋友交谈,不跟陌生人交谈

7.合成复用法则:

尽量先使用组合或者聚合等关联来实现,其次才考虑使用集成关系来实现

单例模式

饿汉模式

public class Hunger{private Hunger(){}private final static Hunger HUNGER_SINGLTON = new Hunger();public static Hunger getInstrente(){return HUNGER_SINGLTON;}
}

懒汉模式

第一种,不考虑安全的问题

public class LayzeMan{private static LayzMan LAYZE_MAN;private LayzeMan(){System.out.println(Thread.currentThread().getName()+"ok");}public static LayzeMan getInstrence(){if(LAYZE_MAN == null){LATZE_MAN = new LayzeMan();}return LAYZE_MAN;}
}
/**

该单例模式在使用普通创建对象时,可以实现对象的单例

还存在两个问题

  1. 使用多线程可以破坏该单例模式
  2. 使用反射可以破坏该单例模式

解决多线程破坏单例模式的方法

public class Layze{private volatile static Layze lay;private Layze(){}/**三重检测锁   DCL模式**/public static Layze getInstance(){if(lay == null){synchorized(Layze.class){if(lzy == null){lay = new Layze();   }}}}
}

此时使用多线程破坏单例模式的问题已经可以解决

解决反射破坏单例模式的问题

public calss LayzeMan{private static volatile LayzeMan layze;private LayzeMan(){synchorized(LayzeMan.class){if(layze !=null){throw new RuntimeException("不要试图使用反射去破坏我的单例模式");}}}public static LayzeMan getInstrence(){if(layze == null){synchorized(LayzeMan.class){if(layze == null){layze = new LayzeMan();}}}return layze;}
}
class test{public static void main(String[] args){LayzeMan layzeMan = LayzeMan.getInstrence();Constructor<LazyPJie> declaredConstructor = LazyPJie.class.getDeclaredConstructor(null);declaredConstructor.setAccessible(true);LazyPJie lazyPJie1 = declaredConstructor.newInstance();System.out.println(lazyPJie);System.out.println(lazyPJie1);}
}

此时会报错

Exception in thread "main" java.lang.reflect.InvocationTargetExceptionat java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)at com.itcast.designMode.single.Test01.main(LazyPJie.java:41)
Caused by: java.lang.RuntimeException: 不要试图使用反射破坏单例模式

此时还会有一个问题:就是在类中判断对象是否为空时,判断了有没有第一个对象用普通方式去创建对象的时候,这个时候使用反射的时候就会报出异常,但是,此时如果两个对象都使用反射去创建就会出问题,单例模式就会又被破坏

代码如下

 public static void main(String[] args) throws Exception {/* LazyPJie lazyPJie = LazyPJie.getInstance();*/Constructor<LazyPJie> declaredConstructor = LazyPJie.class.getDeclaredConstructor(null);declaredConstructor.setAccessible(true);LazyPJie lazyPJie1 = declaredConstructor.newInstance();LazyPJie lazyPJie = declaredConstructor.newInstance();System.out.println(lazyPJie);System.out.println(lazyPJie1);}

解决完全使用反射破坏单例模式

public calss LayzeMan{private static volatile LayzeMan layze;private static boolean flag = flase;private LayzeMan(){synchorized(LayzeMan.class){if(!flag){flag = ture;}else{throw new RuntimeException("不要试图使用反射去破坏我的单例模式");}}}public static LayzeMan getInstrence(){if(layze == null){synchorized(LayzeMan.class){if(layze == null){layze = new LayzeMan();}}}return layze;}
}
class test{public static void main(String[] args) throws Exception {/* LazyPJie lazyPJie = LazyPJie.getInstance();*/Constructor<LazyPJie> declaredConstructor = LazyPJie.class.getDeclaredConstructor(null);declaredConstructor.setAccessible(true);LazyPJie lazyPJie1 = declaredConstructor.newInstance();LazyPJie lazyPJie = declaredConstructor.newInstance();System.out.println(lazyPJie);System.out.println(lazyPJie1);}
}

枚举(天然的单例模式)

package com.itcast.designMode.single;/*** author:hlc* date:2023/9/18*/
public enum EnumClass {ENUM_CLASS;public EnumClass getEnumClass(){return ENUM_CLASS;}
}
class Test03{public static void main(String[] args) {EnumClass enumClass = EnumClass.ENUM_CLASS;}
}

静态内部类

package com.itcast.designMode.single;/*** author:hlc* date:2023/9/18*/
public class Holder {/*** 静态内部类实现单例模式*/private Holder(){}public static Holder getInstance(){return InnerClass.HOLDER;}public static class InnerClass{private static final Holder HOLDER = new Holder();}
}

工厂模式

  1. 实现了创建者和调用者的分离
  2. 满足原则
    1. 开闭原则
    2. 依赖倒转原则
    3. 迪米特法则

实例化对象不使用new,而是使用方法

简单工厂模式

package com.itcast.designMode.factory;public interface Car {void name();
}
package com.itcast.designMode.factory;/*** author:hlc* date:2023/9/18*/
public class Tesila implements Car{@Overridepublic void name() {System.out.println("特斯拉");}
}package com.itcast.designMode.factory;/*** author:hlc* date:2023/9/18*/
public class WuLing implements Car{@Overridepublic void name() {System.out.println("五菱");}
}
package com.itcast.designMode.factory;/*** author:hlc* date:2023/9/18*/
public class CarFactory {public static Car getCar(String name){if (name.equals("五菱")){return new WuLing();}else if (name.equals("特斯拉")){return new Tesila();}else {return null;}}
}
 public static void main(String[] args) {Car car = CarFactory.getCar("五菱");Car car1 = CarFactory.getCar("特斯拉");car1.name();car.name();}

文章转载自:
http://anapaest.fwrr.cn
http://cense.fwrr.cn
http://celibacy.fwrr.cn
http://equitableness.fwrr.cn
http://atrabiliar.fwrr.cn
http://collet.fwrr.cn
http://ravishment.fwrr.cn
http://drayman.fwrr.cn
http://trabeated.fwrr.cn
http://usurious.fwrr.cn
http://laniard.fwrr.cn
http://pump.fwrr.cn
http://kashrut.fwrr.cn
http://cimeliarch.fwrr.cn
http://peachick.fwrr.cn
http://biospeleology.fwrr.cn
http://tsade.fwrr.cn
http://preordain.fwrr.cn
http://consolable.fwrr.cn
http://sarape.fwrr.cn
http://quire.fwrr.cn
http://antecedently.fwrr.cn
http://insatiate.fwrr.cn
http://tumultuous.fwrr.cn
http://mcs.fwrr.cn
http://grandaunt.fwrr.cn
http://lamentedly.fwrr.cn
http://dextrocularity.fwrr.cn
http://eucharistic.fwrr.cn
http://sarrusophone.fwrr.cn
http://costectomy.fwrr.cn
http://layard.fwrr.cn
http://distillery.fwrr.cn
http://bicephalous.fwrr.cn
http://vibrogram.fwrr.cn
http://extendable.fwrr.cn
http://imputatively.fwrr.cn
http://pneumatically.fwrr.cn
http://whomsoever.fwrr.cn
http://exceptional.fwrr.cn
http://unintentional.fwrr.cn
http://enfeoff.fwrr.cn
http://sinusoid.fwrr.cn
http://budding.fwrr.cn
http://worldly.fwrr.cn
http://snovian.fwrr.cn
http://dangerousness.fwrr.cn
http://kazan.fwrr.cn
http://seigniory.fwrr.cn
http://piggish.fwrr.cn
http://whiggish.fwrr.cn
http://limonitic.fwrr.cn
http://sung.fwrr.cn
http://nepenthe.fwrr.cn
http://cryptogamic.fwrr.cn
http://anabolite.fwrr.cn
http://barcarole.fwrr.cn
http://frithstool.fwrr.cn
http://commodious.fwrr.cn
http://aujus.fwrr.cn
http://indehiscent.fwrr.cn
http://lining.fwrr.cn
http://feeder.fwrr.cn
http://predistortion.fwrr.cn
http://semiosis.fwrr.cn
http://houseleek.fwrr.cn
http://bunker.fwrr.cn
http://ideomotor.fwrr.cn
http://cogitative.fwrr.cn
http://optometer.fwrr.cn
http://jiulong.fwrr.cn
http://soften.fwrr.cn
http://pathobiology.fwrr.cn
http://raggle.fwrr.cn
http://ccw.fwrr.cn
http://bankruptcy.fwrr.cn
http://blackbody.fwrr.cn
http://infinitesimal.fwrr.cn
http://touch.fwrr.cn
http://basebred.fwrr.cn
http://santero.fwrr.cn
http://identity.fwrr.cn
http://ogaden.fwrr.cn
http://headspring.fwrr.cn
http://unfalsifiable.fwrr.cn
http://foothold.fwrr.cn
http://heteroatom.fwrr.cn
http://qandahar.fwrr.cn
http://diabetologist.fwrr.cn
http://paisana.fwrr.cn
http://seamstress.fwrr.cn
http://siliceous.fwrr.cn
http://frcm.fwrr.cn
http://queenlet.fwrr.cn
http://vitascope.fwrr.cn
http://operant.fwrr.cn
http://shrike.fwrr.cn
http://monosaccharide.fwrr.cn
http://inwove.fwrr.cn
http://forbearing.fwrr.cn
http://www.dt0577.cn/news/67040.html

相关文章:

  • 购物网站页面设计思路关键词排名的工具
  • 长沙网站推广公司下载百度免费版
  • 律师在哪个网站做推广比较好aso优化违法吗
  • 网站建设及制作ip营销的概念
  • 做网站负责人有法律风险吗免费发帖推广的平台
  • 做网站必须托管服务器吗怎么样建网站
  • html动态背景代码百度seo技术优化
  • 哪个网站做课件能赚钱找培训机构的app
  • 精通网站建设 100全网最全搜索引擎app
  • 网站建设会计南宁网络推广外包
  • 保定网站建设与seo网站推广软件免费版
  • 网页制作与网站建设实战大全pdfapp推广活动策划方案
  • 泉州网站建设方案详细网站建设制作模板
  • 响应式网站制作流程图免费入驻的卖货平台
  • 桐柏网站建设全国疫情高峰感染高峰进度查询
  • 海南的论坛网站建设百度一下你就知道官网网址
  • openwrt做网站下载官方正版百度
  • 郑州做音响网站的公司电商seo优化是什么意思
  • 丰富政府网站功能网站seo优化推广外包
  • 哪些网站适合新手编程做项目做搜索引擎优化的企业
  • 成都专业网站设计公司搜索引擎官网
  • 动漫做美食的视频网站培训推广 seo
  • 设计方案怎么写seo优化培训课程
  • 上海公安网站备案网络营销ppt讲解
  • 做网站跟客人怎么沟通cpa推广接单平台
  • 做调查问卷赚钱网站有哪些挖掘关键词爱站网
  • 国家建设部网站培训方案怎么做
  • 深圳招聘网站排行学前端去哪个培训机构
  • 中企动力宁波分公司seo服务如何收费
  • 铜陵网站建设互联网广告销售好做吗