软件开发方法:复用与扩展

软件开发方法:复用与扩展

一、面向对象

封装 工程上的意义:屏蔽细节,隔离变化 public、protected、private

继承 工程上的意义:复用

多态工程上的意义:高内聚,低耦合 ------ 面向对象核心

二、进一步认识

  • 遵循已有框架规则,搭建程序,学习框架使用
  • 遵循框架提供的接口和调用规则
  • 扩展别人的功能
cpp 复制代码
#include "QtWidgetsApplication.h"
#include <QtWidgets/QApplication>
#include <QLabel>
#include "stdlib.h"

class NewLabel :public QLabel {
public:
  NewLabel(QString str) :QLabel(str) {

  }
  void runCommand() {
	system("notepad");
  }
};

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

	NewLabel label("a");
	label.show();
	label.runCommand();

    return a.exec();
}

上面是对Qt中QLabel扩展的举例


推荐一个零声学院项目课,个人觉得老师讲得不错,分享给大家:
零声白金学习卡(含基础架构/高性能存储/golang云原生/音视频/Linux内核)
https://xxetb.xet.tech/s/VsFMs

相关推荐
·present·5 小时前
CSAPP(lecture 4_01)
c语言·c++
FPGA小迷弟5 小时前
用 Claude Code 重构遗留系统:从评估到落地的完整实践指南
c++·python·ai·plotly·django·ai编程·claude
程序员-King.5 小时前
【ROS1】Noetic 开发工作流程与常用命令
c++·ubuntu·ros
云深麋鹿5 小时前
C++ | 基于红黑树实现mymap与myset
开发语言·c++
傲世仙尊7 小时前
string增删查改-insert-erase-replace与find加substr组合技
c++
dyxal8 小时前
A2A 协议 v1.0 完全指南:方法名、Agent Card、三种绑定与 FastAPI 实战
开发语言·qt·fastapi
·present·8 小时前
CSAPP(lecture 3)
c++
别动我齐刘海9 小时前
机器人 C++ / 系统联调补强2——异常处理、Protobuf
linux·c++·人工智能·学习·算法·机器学习·机器人
basketball6169 小时前
C++ 中字符串与常见类型的转换总结
开发语言·c++
等我调个Bug9 小时前
C++智能指针通俗讲解
开发语言·c++