设计模式
基于 Design Patterns: Elements of Reusable Object-Oriented Software 编写
介绍
设计模式有四大必备元素:
模式名
问题:何时应用此模式
解决方案:应用于不同情况下的模板
后果:应用该模式的结果与取舍
多种设计模式可以组合使用,事实上也经常组合使用
设计模式解决问题的方法:
找到合适的对象
确定对象的粒度
具体说明对象接口
具体说明对象实现
类与接口继承
给接口编程,而不是向实现
为了让复用机制生效
继承与组合——倾向于组合
指派
继承与参数化类型
运行时和编译时结构
aggregation:一个对象拥有另一个对象,即两者有相同的生命周期
acquaintance:一个对象仅仅知道另一个对象
为改变而设计:
通过
应用程序:
工具集
框架
创建模式
抽象工厂 Abstract Factory
目的:在具体说明具体类的情况下创建相关的对象家族
应用
一个应该被配置为多种产品家族之一的系统
一个家族的相关产品被一起使用
提供一类库的产品
结构
参与者
抽象工厂 - 具体工厂
抽象产品 - 具体产品 ...
Effective C++
基于 Effective C++ Third Edition: 55 Specific Ways to Improve Your Programs and designs 编写
让你自己习惯于 C++
将 C++ 视为语言的联邦
C++ 不是一门单独的语言,其具有各种不同风格的语言特性,以至于可能出现两个同样使用 C++ 的人会看不懂彼此的代码。一般分为四大组成部分:
C
面向对象的 C++
模板 C++
STL
因此基于使用的 C++ 的部分不用,Effective C++ 编程的规则也可能不同
倾向于 const、enum 和 inline 而不是 #define
对于变量而言,const 和 enum 限制了作用域
对于函数而言,inline 函数能够避免一些未知错误
尽可能使用 const
声明某种东西 const 可以帮助编译器检测一些使用错误,同时 const 可以适用于任何作用域中的对象,包括函数参数,返回值,甚至整个成员函数
编译器强制 bitwise const,但应该使用逻辑 const 编程
当 const 和非 const 成员函数有相同的实现时,可以让非 ...
Java 开发手册
基于 Alibaba 的 Java 开发手册编写
编程规约
命名风格
类名:UpperCamelCase,其余使用 lowerCamelCase,常量全部大写
抽象类使用 Abstract 开头,异常类使用 Exception 结尾,测试类以要测试的类的名称开始,以 Test 结尾
包名统一使用单数形式
在变量命名时,表示类型的名词放在结尾,如 nameList
设计模式应该体现出来
接口类中不要加任何修复符号
Service/DAO 层命名规约:
获取单个对象:get
获取多个对象:list,并复数结尾
获取统计值用 count
插入 insert
删除 remove
修改 update
领域模型:
数据对象:数据表名 + DO
数组传输对象:业务领域相关的名称 + DTO
展示对象:网页名称 + VO
OOP 规约
所有整型包装类对象之间值的比较,均使用 equals
BigDecimal 使用 compareTo() 方法比较
所有 POJO 类属性和 RPC 方法必须使用包装数据类型,局部变量使用基本数据类型
集合处理
Comparator ...
IntelliJ IDEA
IntelliJ IDEA 是 Java 和 Kotlin 的知名 IDE,简单而功能强大
插件推荐
Chinese (Simplified) Language Pack / 中文语言包
我判断一个外国工具是否流行的唯一依据是其是否支持中文。 ——沃兹基·硕德
CodeGlance Pro
侧边栏显示代码缩略图,类似与 VS Code 的功能
Rainbow Brackets
彩虹括号,可惜是付费的,但也有免费的版本:Rainbow Brackets Lite
Alibaba Java Coding Guidelines(XenoAmess TPM):基于 Java 开发手册,提供了一系列的代码检查和修复功能
Json Parser:验证和格式化 JSON 字符串的工具
Grep Console:给控制台输出标上颜色,过滤输出等
Atom Material Icons:IDEA 版的 Material 图标库
RestfulTool
方便查看 Restful 服务开发
C++ 入门(下)
关联型容器 Associative Containers
关联型容器通常需要键满足 <,否则可以自定义一个:
bool compareIsbn(const Sales_data &lhs, const Sales_data &rhs) { return lhs.isbn() < rhs.isbn();}multiset<Sales_data, decltype(compareIsbn)*> bookstore(compareIsbn);
关联性容器定义了三种类型:
key_type
mapped_type
value_type
set:key_type
map:pair<const key_type, mapped_type>
set 的迭代器都是 const_iterator
.lower_bound() >=,.upper_bound() >,.equal_range()
除此之外,还有键可以重复的 multiset 和 multimap
unordered_set 和 unorde ...
Makefile
介绍
Makefile 的基本规则:
target ... : prerequisites ... recipe ... ...
target:可以是一个 object file(目标文件),也可以是一个可执行文件,还可以是一个标签(label)
prerequisites:生成该 target 所依赖的文件和/或 target
recipe:该 target 要执行的命令(任意的 shell 命令)
简单来说就是指定了一个依赖关系
输入 make 命令时,是这么工作的:
make 会在当前目录下找名字叫 Makefile 或 makefile 的文件
如果找到,它会找文件中的第一个目标文件(target),并把这个文件作为最终的目标文件
如果该文件不存在,或其所依赖的后面的 .o 文件的文件修改时间要比这个文件新,则执行后面所定义的命令来生成这个文件
如果所依赖的 .o 文件也不存在,那么 make 会在当前文件中找目标为 .o 文件的依赖性,如果找到则再根据那一个规则生成 .o 文件
最后用 .o 文件生成可执行文件
在 Makefile 中可以声明变量并 ...
VS Code
VS Code 是流行的代码编辑器,可以通过插件支持各种语句的高亮、调试、编译等
设置
字体喜欢使用 JetBrains Mono,字号设为 14,并开启连字
快捷键
功能
快捷键
功能
快捷键
移动行
alt + up / down
查找文件
ctrl + p
显示相关插件的命令
ctrl + shift + p 或 F1
多行同时添加内容(光标)
ctrl + alt + up / down
光标跳到下一个单词
ctrl+ left / RIGHT
行增加/减少缩进
ctrl + [ / ]
隐藏底部控制面板
ctrl + j
显示/隐藏左侧目录栏
ctrl + b
语言支持
Markdown
Markdown All in One
几乎涵盖了大部分内容
Markdown Preview Enhanced
Markdown 预览
Unicode Latex
将 Latex 符号转化为 Unicode 符号,更容易辨认
JavaScript/TypeScript + React
原生支持(毕竟 VS Code 就是用 TypeScript 编写的,所 ...
C++ 入门(上)
基于 _C++ Primer Fifth _ 编写
不愧是 C++,这才只是入门,只到 C++ 11
开始 Getting Started
万恶之源:
#include <iostream>int main() { std::cout << "Hello, world!" << std::endl; return 0;}
文件的后缀名有很多,最常见的应该是 .cc 和 .cpp
编译器也有很多,如使用 g++ 编译:
g++ -o prog1 prog1.cc
添加支持 c++ 11 标准:-std=c++11
-Wall 生成更多警告信息
输入输出:
这里使用了 iostream 库中的标准输入流和标准输出流,该库中还有标准错误流 cerr 和 clog
<< 是输出操作符,>> 是输入操作符
endl 是一种控制符 manipulator,有结束当前行和刷新缓冲区的作用
std:: 表示使用命名空间 namespace 的函数等,用于区分
一个读入的例子:
std ...
Spring Boot
Maven
Maven 可以用于管理 Java 项目的依赖
在 pom.xml 文件中指定了 Maven 坐标,其构成如下:
groupId:通常是域名反写
artifactId:通常是模块名称
version:版本号
引入依赖:在 <dependencies> 标签下,使用 <dependency> 引入标签,并定义 Maven 坐标
依赖有传递性,可以使用 <exclusion> 手动排除依赖的资源
使用 <scope> 设置其作用范围,通常使用默认的和 <test>
Maven 有 3 套独立的生命周期:
clean
default:编译、测试、打包、部署等
site:生成报告、发布站点
可以手动执行其中的若干个生命周期
请求与响应
Tomcat 是一个轻量级的 web 服务器,支持 Servlet 规范
几种请求参数:
简单参数:名字一致,也可以使用一个对象接收多个参数
GET http://localhost:8080/simpleParam?name=Tome@RequestMapping("/s ...
Java
基于 Bruce Eckel 的 On Java 8 编写
什么是对象 What is an Object?
面向对象编程的特点:
任何东西都是对象
程序是一堆通过发消息告诉彼此的对象(调用对象的方法)
每个对象有由其它对象组成的内存
每个对象都有一个类型(类是一个实例)
一个特定的类型的所有对象可以收到相同的信息
也可以说:对象有声明(内部数据)、表现(方法)和身份(唯一的内存地址)
对象有接口
对象通过方法提供服务
隐藏的实现——封装
重复利用实现——继承
是和像的关系
多态
单根继承
集合
泛型
对象的生命周期——有垃圾收集器
到处都是对象 Objects Everywhere
使用引用操作对象
原始类型,特别的,有“类包装”,如 Character
有方便的数组
注释常见每一行开头有一个 *,尽管是不必要的
有作用域,无需手动销毁对象
创建新的数据类型:class
域中的原始成员数据默认值为 0,但局部变量随机
Java 中防止名称重复的方法是反向使用域名,如域名为 MindviewInc.com 中的 foibles utility 则包名称为 com.mindviewi ...