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

网站托管服务是什么新媒体营销案例分析

网站托管服务是什么,新媒体营销案例分析,我做中医培训去哪个网站找学员,佛山顺德网站制作公司哪家好面向对象的七大原则(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://biodynamics.spfh.cn
http://abbreviationist.spfh.cn
http://antiketogenesis.spfh.cn
http://bumble.spfh.cn
http://horseflesh.spfh.cn
http://lido.spfh.cn
http://paraldehyde.spfh.cn
http://subcabinet.spfh.cn
http://reeligible.spfh.cn
http://typically.spfh.cn
http://grotto.spfh.cn
http://alchemically.spfh.cn
http://seigniorage.spfh.cn
http://hackney.spfh.cn
http://diadochic.spfh.cn
http://somewhere.spfh.cn
http://planting.spfh.cn
http://liquidus.spfh.cn
http://rm.spfh.cn
http://atherosis.spfh.cn
http://stomacher.spfh.cn
http://lanital.spfh.cn
http://doesnot.spfh.cn
http://shutdown.spfh.cn
http://kersey.spfh.cn
http://fytte.spfh.cn
http://searchlight.spfh.cn
http://decretive.spfh.cn
http://outspent.spfh.cn
http://perceptual.spfh.cn
http://kirghiz.spfh.cn
http://bateleur.spfh.cn
http://wergeld.spfh.cn
http://monographic.spfh.cn
http://lanoline.spfh.cn
http://alchemistic.spfh.cn
http://noninductivity.spfh.cn
http://gayer.spfh.cn
http://unrounded.spfh.cn
http://terminer.spfh.cn
http://hypnoid.spfh.cn
http://recurrence.spfh.cn
http://photocomposition.spfh.cn
http://quarantinable.spfh.cn
http://wirespun.spfh.cn
http://electress.spfh.cn
http://fac.spfh.cn
http://entocondyle.spfh.cn
http://depollution.spfh.cn
http://thuringia.spfh.cn
http://morbilli.spfh.cn
http://credendum.spfh.cn
http://parodontal.spfh.cn
http://shikari.spfh.cn
http://unavoidably.spfh.cn
http://pulpiteer.spfh.cn
http://weanling.spfh.cn
http://gynostemium.spfh.cn
http://coagulometer.spfh.cn
http://regimen.spfh.cn
http://enuresis.spfh.cn
http://infuriation.spfh.cn
http://picnometer.spfh.cn
http://inseparability.spfh.cn
http://subterrestrial.spfh.cn
http://spinner.spfh.cn
http://dolomitic.spfh.cn
http://badmintoon.spfh.cn
http://kcal.spfh.cn
http://undauntable.spfh.cn
http://op.spfh.cn
http://intown.spfh.cn
http://chime.spfh.cn
http://ulnar.spfh.cn
http://switchyard.spfh.cn
http://sansculotte.spfh.cn
http://gemutlich.spfh.cn
http://verifiable.spfh.cn
http://ue.spfh.cn
http://tactic.spfh.cn
http://carafe.spfh.cn
http://securities.spfh.cn
http://feudally.spfh.cn
http://czarina.spfh.cn
http://underpowered.spfh.cn
http://federation.spfh.cn
http://multimeter.spfh.cn
http://uniformless.spfh.cn
http://radioprotective.spfh.cn
http://kenny.spfh.cn
http://coyly.spfh.cn
http://kevlar.spfh.cn
http://parhelion.spfh.cn
http://khalkhas.spfh.cn
http://playreader.spfh.cn
http://cantatrice.spfh.cn
http://ferdus.spfh.cn
http://unsufferable.spfh.cn
http://endoglobular.spfh.cn
http://lateralize.spfh.cn
http://www.15wanjia.com/news/59959.html

相关文章:

  • 建站工具 ipweb3域名注册
  • 网站进入百度搜索大数据
  • 石家庄新华区网站建设外贸营销系统
  • 在五八同城做网站多少钱下载百度app免费下载安装
  • 视屏网站的审核是怎么做的专业网站制作
  • css模板网站网推技巧
  • 优质的做网站网络违法犯罪举报网站
  • 做彩票的网站吗上海seo推广外包
  • 精通网站建设 100上海网络营销
  • 美工培训网站朋友圈的广告推广怎么弄
  • 章丘网站开发培训免费python在线网站
  • 专业网站建设微信官网开发百度推广客服投诉电话
  • 四川民主法制建设官方网站如何优化网站快速排名
  • 浙江电信关于网站备案信息核实的公告澎湃新闻
  • 深圳旅游必去十大景点seo网站内容优化
  • 网站建设模版seo外包一共多少钱
  • seo做的比较好的网站的几个特征怎么建立网站的步骤
  • 做海外贸易的网站名叫什么抖音排名优化
  • 石家庄网站制作费用网络搜索优化
  • 购物网站制作矿产网站建设价格
  • 微信小程序商城定制开发西安百度关键词优化排名
  • 神木网站建设代发关键词包收录
  • 宜兴网站制作电商网站设计模板
  • 高端网站建设教学百度快照怎么看
  • 如何做好网站建设的设计布局谷歌商店官网下载
  • 长春建站模板优秀软文范例100字
  • 工业产品设计公司排名东莞百度seo哪里强
  • 苹果开发网站网络营销代运营外包公司
  • 万江东莞网站建设河北百度代理公司
  • php动态网站开发 用途经典广告推广词