软件设计原则与UML类图

软件设计原则与UML类图 1 软件设计原则 开闭原则(Open Closed Principle, OCP):对扩展开发,对修改关闭 单一职责原则(Single Responsibility Principle, SRP):一个类只负责一个功能领域中的相应职责 里氏替换原则(Liskov Substitution Principle, LSP):所有引用基类的地方必须能透明地使用其子类对象 依赖倒置原则(Dependency Inversion Principle, DIP):依赖于抽象,不能依赖于具体实现 接口隔离原则(Interface Segregation Principle,ISP):类之间地依赖关系应该建立在最小的接口上 合成/聚合复用原则(Composite/Aggregate Reuse Principle,C/ARP):尽量使用合成/聚合,而不是用过继承达到复用的目的 最少知识原则(Least Knowledge Principle,LKP)或迪米特法则(Law of Demeter, LOD):一个软件实体应当尽可能少的与其他实体发生相互作用。 2 UML类图 3 Spring使用了哪些设计模式 工厂设计模式:Spring使用工厂模式通过Beanfactory、ApplictionContext创建Bean对象 代理设计模式:Spring AOP功能的实现 单例设计模式:Spring中的Bean默认都是单例的 模板方法模式:Spring中jdbcTemplate、hibernateTemplate等以Template结尾对数据库操作的类 包装器设计模式: 观察者模式:Spring事件驱动模型 适配器模式:Spring AOP的增强或者通知使用到了适配器模式,Spring MVC中也使用了适配器模式适配Controller 4 JDK使用了哪些设计模式 桥接模式 适配器模式 组合模式 装饰器模式 享元模式 代理模式 抽象工厂模式 建造者模式 工厂方法 原型模式 单例模式 责任链模式 命令模式 解释器模型 中介者模式 备忘录模式 空对象模式 观察者模式 状态模式 策略模式 模板方法模式 访问者模式

September 26, 2024 · 1 min · 69 words · RLTEA

零碎知识点

零碎知识点 1 Java 原子类中,CAS是如何保证原子性的? 原子类中,用volatile修饰value,并使用unsafe类获取到value的地址偏移量,在执行更新操作时,使用unsafe类执行compareAndSwap操作,而该方法是一个Native方法,底层是通过汇编指令CMPXCHG加上Lock前缀,保证内存区域只允许一个线程访问。 2 运行时多态和编译时多态 运行时多态:通过基类或者抽象类、虚函数等调用具体实例的方法,在运行时才可以确定具体方法,这种情况时运行时多态。 编译时多态:函数的重载、模板类等,在编译时即可确定具体的方法,这种情况是编译时多态。 3 B树的具体应用 降低磁盘IO? 4 C++和Java的堆栈有什么区别 栈内存更快,但是堆内存更加灵活。 编译期间没有办法确定堆空间上的内存分配情况,堆上分配的内存需要回收(C++需要程序员手动回收,而Java有自动垃圾回收机制);而栈内存的内存回收由系统管理。 C++的对象既可以创建在堆上,也可以创建在栈上,Java绝大多数对象都创建在堆上。Java中的栈一般情况只存储引用和基本变量。 C++用alloca申请栈内存,new申请堆内存,malloc申请自由存储区,此外还有全局(静态)存储区用于存储全局变量和静态变量,常量存储区存储常量。 注意:栈中申请的内存都需要使用指针指向,Java也是如此,只不过对程序员屏蔽掉了指针。 5 C++的内存分布 由上至下分别是:栈、堆、全局区、常量区、代码区。 堆区内存向上增长,栈区内存向下增长。 https://blog.csdn.net/qq_72982923/article/details/132197354 6 Java中的对象内存分配 栈上内存分配:当对象的生命周期与入栈的方法一致时,JVM的对象逃逸分析会让该对象直接在栈上进行空间分配,从而减少GC压力 堆上内存分配:对象优先在eden区分配,大对象直接进入老年代,eden区对象经过GC后,如果存活,则存入survivor区并增加年龄,当年龄达到阈值,会进入老年代(注意:当survivor区内存不足时,会动态调整年龄阈值,将对象送入老年代)。老年代空间分配担保机制:指的是minorGC前会计算老年代剩余空间和年轻代中的对象大小,如果空间不足,则触发一次FullGC,如果垃圾回收后空间不足则会触发OOM。 7 进程的内存分配 内核区(用户不可读写)高地址段 栈(向下增长) 堆(向上增长) 数据段 代码段 https://blog.csdn.net/xyxzlsld666/article/details/132393872 8 Redis中的ListPack是什么 listpack:… :4字节,表示listpack占用字节数 :2字节,元素个数 :entry ...

September 26, 2024 · 1 min · 61 words · RLTEA

计算机网络基础

1 TCP/IP网络模型 应用层:工作在用户态,有HTTP、FTP、Telnet、DNS、SMTP协议。 传输层:为应用层提供网络支持作用,有TCP和UDP协议。 网络层:负责实际的传输工作,将数据从一个设备传输到另一个设备,有IP协议等。 网络接口层:为网络层提供**“链路级别”**的传输服务,负责在以太网、Wifi这样的底层网络上发送原始数据包,工作在网卡这个层次,使用MAC地址标识网络上的设备。 网络接口层的传输单位是帧(frame),IP 层的传输单位是包(packet),TCP 层的传输单位是段(segment),HTTP 的传输单位则是消息或报文(message)。但这些名词并没有什么本质的区分,可以统称为数据包。 2 从键入网址到网页显示,期间发生了什么? 浏览器解析URL,生成HTTP请求 通过DNS查询真实地址:浏览器先查看自身缓存,然后询问操作系统,操作系统查看自身缓存,然后查看hosts文件,最后询问本地DNS服务器。DNS有轮询和递归两种访问策略,DNS客户端和本地服务器之间是递归策略,而本地服务器和其他DNS服务器之间是迭代轮询。 将HTTP数据报文的传输工作交给操作协调的协议栈。 应用程序调用socket库,委托协议栈工作。 协议栈的上半部分有两块,分别是负责收发数据的 TCP 和 UDP 协议,这两个传输协议会接受应用层的委托执行收发数据的操作。 协议栈的下面一半是用 IP 协议控制网络包收发操作,在互联网上传数据时,数据会被切分成一块块的网络包,而将网络包发送给对方的操作就是由 IP 负责的。 此外 IP 中还包括 ICMP 协议和 ARP 协议。 ICMP 用于告知网络包传送过程中产生的错误以及各种控制信息。 ARP 用于根据 IP 地址查询相应的以太网 MAC 地址。 IP 下面的网卡驱动程序负责控制网卡硬件,而最下面的网卡则负责完成实际的收发操作,也就是对网线中的信号执行发送和接收操作。 通过网卡传输二进制数据 交换机和路由器转发数据包 服务端层层拆包 返回响应走相同流程,浏览器收到响应后渲染页面 ...

August 18, 2024 · 1 min · 155 words · RLTEA

How to build this blog website

Preparation Github Account Needed: First, you need a github account. If you don’t have, don’t know, and don’t even ask google how to do, just see this blog HOW TO GET A GITHUB ACCOUNT. Two Special Repository Needed: Your need to create your github.io repository and fork SlothBlog repository, the forked repository we will call it “shadow repo” in the following content. We also prepare a guide book for this step here. Two Branch Needed: Please make sure that your github.io repository have “main” branch and “static” branch, and each of them have at least one commit. Simple Guide Generate a GitHub token, and make sure that this token have enough authority.Then open the setting page of shadow repo, add two repository secret for actions. ...

June 28, 2024 · 2 min · 277 words · RLTEA

How to create a repository

Create Repository Create the io repository Click create repository button, and chose “new repository”. Enter the repository name, which must match the “username.github.io” format, and don’t forget replace the “username” with yours. Scroll all the way down, and click the “create repository” button. Fork the RoaraeonLiou/SlothBlog repository.

June 28, 2024 · 1 min · 47 words · RLTEA

How to get a github account

Get a Github Account Here is the link of GitHub , click it and sign up a github account. If you really don’t know how to do it, no worry, just follow me. Click sign up button Click the continue button Set password Set username Click the continue button all the way, and follow the guidance of github to verify your account. When you finish the 5th step, you will receive an email, which contains the code that you need to fill in the boxes shown in the following picture. ...

June 28, 2024 · 1 min · 102 words · RLTEA

How to organize the blogs

Organization See Content Organization. . └── content ├── posts | ├── firstpost.md // <- https://xxx.github.io/posts/firstpost/ | ├── happy | | └── ness.md // <- https://xxx.github.io/posts/happy/ness/ | └── secondpost.md // <- https://xxx.github.io/posts/secondpost/ └── docs ├── first.md // <- https://xxx.github.io/docs/first/ └── second.md // <- https://xxx.github.io/docs/second/ Header If you want to do some basic settings for your blog, you can add your own header definition. Fields Basic Header Fields +++ title = "title" description = "write your description" author = "rltea" slug = "define_your_slug" draft = false date = "2024-06-25" lastmod = "2024-06-28" url = "/posts/new_blog" tags = ["new", "blog"] include_tags = ["test", "old"] exclude_tags = ["sloth"] categories = ["new", "blog"] include_categories = ["old", "test"] exclude_categories = ["sloth"] status = "update" +++ blog content As shown in above, between the two “+++” lines, there are the header information of one markdown blog file which in toml format. You can also define the header in yaml format enclosed in “---”, or write directly in json format. ...

June 28, 2024 · 3 min · 562 words · RLTEA

Support Comment

Giscus comment We use the github app giscus to make the comment function works. You need to install this app to your username.github.io repository, and than configure it in giscus app page, enter your io repository, and choose a mapping rule(we suggest the Discussion title contains page <title> mapping rule). Copy the generated script, copy it in layouts/partials/comment.html.

June 28, 2024 · 1 min · 58 words · RLTEA

Support Latex

Support Latex According to the hugo official document of release v0.122.0, we already make the mathematics support as defalut if you use the default theme PaperMod. If you want to use other themes, make sure that you have set the following config in config/hugo.yaml. markup: goldmark: extensions: passthrough: delimiters: block: - - \[ - \] - - $$ - $$ inline: - - \( - \) - - $ - $ enable: true params: math: true And create the layouts/partials/math.html file which content as follow: ...

June 28, 2024 · 1 min · 206 words · RLTEA