当前位置:网站首页>代码大全读后感
代码大全读后感
2022-06-29 16:07:00 【qq_1410888563】
一:80页:理想设计特征
1.最小复杂度

见解:
1.尽量减小复杂度,比如查询的时候可以用快排
2.用存储结构的时候,频繁插入删除用list,频繁查找用vector
3.不涉及到排序的时候尽量用unordered类型
4.for循环嵌套,小循环嵌套大循环
二:93页:信息隐藏的一个例子
有个程序,其中每个对象都是通过名为id的成员变量存储唯一的ID。
简单的方式就是设置一个全局变量g_id,其他对象构造的时候,简单使用id =++g_id;
正确的做法是:
设计一个接口
NewId() { return(++g_id);};
id=NewId();
三:93页:非标准语言特性

见解:
将外部库封装在函数里面去调用,而不要直接调用。
后面如果要替换起来也比较容易。
四:100页:耦合标准
有一个公用函数,需要两个参数,而这两个参数是某个类的数据。
这个函数的正确设计应该是用这两个参数作为函数的参数。而不是用类作为参数。

五:102页:语义上的耦合

见解:
如果有两个类,我们设计的时候,不能因为A知道B需要什么,就提供具体的操作,比如A有初始化init函数,然后A中有Run函数,Run函数无论如何都会调用init函数。然后B直接调用Run函数。A知道B实际上只用到7个初始化数据中的3个。所以A只初始化3个数据。这就是语义的耦合。非常危险。
正确做法:
B应该调用A的init,A中的初始化可以全部数据初始化,或者写一个函数专门初始化需要的3个数据。
边栏推荐
- 稳定币风险状况:USDT 和 USDC 安全吗?
- leetcode:42. Rain water [double hands are elegant]
- leetcode:139. Word splitting [DFS + memory]
- 实践 | 移动端图片上传旋转、压缩的解决方案
- Sophon kg upgrade 3.1: break down barriers between data and liberate enterprise productivity
- 星环科技数据安全管理平台 Defensor重磅发布
- The third sprint of Wei long La Tiao: the growth rate of performance declined, and Liu Weiping and Liu Fuping cashed out in advance
- 按键精灵打怪学习-窗口绑定保护技能和点击技能
- Sophon autocv: help AI industrial production and realize visual intelligent perception
- C language -- printf print base prefix
猜你喜欢
随机推荐
Cv5200 ad hoc network remote WiFi module, UAV wireless image transmission application, HD low delay scheme
How do I create a contact form in WordPress?
『计组』CPU 如何区分指令和数据
BOE: with the arrival of the peak season in the second half of the year, the promotion and the release of new products, the demand is expected to improve
mysql数据库基础:DDL数据定义语言
How to embed iframes in WordPress
真正的测试 =“半个产品+半个开发”?
能够1年涨薪2次的软件测试工程师,他到底强在哪里?
MySQL常用语句和命令汇总
隐私计算助力数据的安全流通与共享
【OpenGL】杂谈一、通过鼠标拖拽实现相机绕空间中的某点进行球面旋转查看
leetcode:139. Word splitting [DFS + memory]
如何在网站上安装 WordPress
【第28天】给定一个字符串S,请你判断它是否为回文字符串 | 回文的判断
Self taught programming can understand the code, but what if you can't write it yourself
Telnet+ftp to control and upgrade the equipment
Key sprite fighting monsters - window binding protection skills and click skills
leetcode:232. Realize queue with stack [two stacks, one auxiliary and one simulated queue]
Profil de risque de monnaie stable: l'usdt et l'USDC sont - ils sûrs?
同样是做测试,为什么别人年薪30W+?









