封装sdk包 c++_大型 SDK 组件化拆分的一些思考

本文介绍了在面临大型SDK组件化拆分的需求时,作者通过分析现有问题,如组件依赖、通讯方向等,探讨了如何进行横向和纵向切割,以及如何利用中介者模式实现组件间通讯。文章还提到了清理废弃代码、数据流向划分、保底方案和最终采用的多中介者模式,强调了设计原则和注意事项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2ac4e5a31b94ec4d6bbc321e9e7a6867.png

笔者所在部门都一个很大的SDK,被公司众多部门所使用,笔者到来之前,这个SDK采取的是原始的开发方式,随着时间的迁移,已经变得非常大,大概一千多个OC文件,C++的没数过,功能也很丰富,但是对于某些部门,对包大小有非常严格的限制,某些不需要的功能需要减包,对于一个高度耦合在一起的SDK来说,几乎只能通过预编译宏来减少文件的引用,这样做造成一个git仓库上维护着多个分支,每次合并都是噩梦般地存在,而且由于功能模块很多,对于每一个功能模块都需要有一个预编译宏,这样带来一个问题,如果宏的组合发生错误,那么这个极有可能带来严重BUG。因为笔者面试的时候,和面试官除了常规技术问题,谈得最多的是架构设计,所以当笔者进入公司之后,总监以及组长都希望我能够解决掉现在的问题,至少说能够部分解决,特别是大ZT计划发布之后,这件事被真正意义上的开始实施。笔者这篇文章是一篇随笔,是希望为遇到同样的事情的开发者提供一些思路,由于保密的原因,有很多东西没有办法说清楚,忘见谅,勿喷。

需求

笔者的任务在初期是比较简单和明确的,要求对于某些模块能够可选集成,使用cocoaPod的时候,是否集成某个模块,不能改动一句代码,有点像友盟的社会组件集成方式,但是比那个应该要复杂一些,后面会细说原因。

看到这里,有经验的朋友第一个想到的就是组件化,组件化已经不是什么稀罕事儿了,业内有非常成熟的URL注册方案Mediator方案以及Protocol注册方案

使用C++代码封装的win32操作类, 与MFC相似,对于学习SDKC++是巨好的参考 Tutorials Menu of tutorials Tutorial 1: The Simplest Window Tutorial 2: Using Classes and Inheritance Tutorial 3: Using Messages to Create a Scribble Window Tutorial 4: Repainting the Window Tutorial 5: Wrapping a Frame around our Scribble Window Tutorial 6: Customising Window Creation Tutorial 7: Customising the Toolbar Tutorial 8: Loading and Saving Files Tutorial 9: Printing Tutorial 10: Finishing Touches Tutorial 1: The Simplest Window The following code uses Win32++ to create a window. This is all the code you need (in combination with Win32++) to create and display a simple window. Note that in order to add the Win32++ code to our program, we use an #include statement as shown below. #include "../Win32++/Wincore.h" INT WINAPI WinMain(HINSTANCE, HINSTANCE, LPTSTR, int) { //Start Win32++ CWinApp MyApp; //Create a CWnd object CWnd MyWindow; //Create (and display) the window MyWindow.Create(); //Run the application return MyApp.Run(); } This program has four key steps: Start Win32++. We do this here by creating a CWinApp object called MyApp. Create a CWnd object called MyWindow. Create a default window by calling the Create function. Start the message loop, by calling the Run function. If you compile and run this program, you'll find that the application doesn't end when the window is closed. This is behaviour is normal. An illustration of how to use messages to control the windows behaviour (including closing the application) will be left until tutorial 3.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值