Preface
For two sides and three sides of byte beating ,Framework+MVP framework +HashMap principle + performance optimization +Flutter+ Source code analysis and other issues have become high-frequency questions ! However, many of my friends can't answer or answer completely in the interview ! Today, I'd like to share with you the video analysis of these questions , Hope to help friends in need !
80% The interview questions that most people can't answer —Framework
Video content summary :
1.framework Layer as a whole to perform process analysis 2.XML File loading source code analysis 3. Customize VIEW Source code analysis 4. Cut into the source code execution process to achieve screen adaptation
The handwriting structure , Here's the problem :
1、 Give Way App Inside Each functional module can develop unit tests independently , It's fine too All modules are integrated and packaged , Unified testing
Independent development
change gradle.properties Configuration of , Make each functional module application, Can be packaged into apk, Separate operation . Single module , Independent testing .
Integrated packaging
change gradle.properties Configuration of , Make each individual module , All become library, By Main module reference , At this time, only the main module can be packaged apk, All functions are integrated in this apk Inside .
2、 Realization Overall transplantation of functional modules , Flexible plugging
The story background
When your company has multiple Android developers , Develop the same core business , however UI Different , A series of different businesses App when ( If the core business is X, You have 5 Developers , To make the A,B,C,D,E 5 individual app, Both contain core business X, But in addition to X outside , Other business modules are different ) Now , If the leader wants to A There is a non core function , Move to B Inside ...
present situation
Development B The program ape may curse his mother , Because he's transplanting from A Split code from the code Encountered a lot of high coupling , Low cohesion Class structure of , After moving over , Pull one hair and move the whole body , Move a little bit , whole
《Android Summary of learning notes + Latest mobile architecture video + Big Android interview questions + Project actual combat source code handout 》 Free open source Hui Xin search official account 【 Advanced programming 】
Code man Jianghong .
Ideal
If this time , We use the configuration of the code framework , Can handle A A module inside ,
As a module
Migration to Inside the project , Then master module To quote this module, Write a little code to make this function module in app Enter into force . So no matter how many functional modules , Can be taken as a whole To others app Reuse . So developers don't have to swear at each other , If the module moved over exists bug Or other questions , You don't have to throw the pot , Who originally developed the module , Just find someone .
3、 Guarantee App Inside Isolation of business modules , But it does not hinder the data interaction between business modules
We develop app Functional module of , A business , Maybe through a Activity perhaps One Fragment As a window to the outside world , It could be .*** The so-called window , This is the business , Relative to other modules ," Yes and only " An entry , There is no other way to reach this business .*** Business codes are isolated from each other , There must be no cross references . that , Since they don't reference each other , that A Modules must use B Module data , What shall I do? ? Solutions are provided below .
Text outline
1、 Code structure status and ideal state list
2、 The realization idea of function componentization , Implement component migration and plug-in
3、 Reference resources ARouter Source code , Write your own Router frame , To pass through Router To switch modules as well as Data interaction between components
4、 Use components api turn , Optimize the structure of common modules when there are many modules
Text
1、 Code structure status and ideal state list
present situation ;

The code shows signs of modularity , But there is no obvious modularization of business modules ( I don't know what that means, do I ? Just don't understand ,app This module There are actually a lot of things that haven't been shown , Please look at the chart below. : Just imagine , Put all the modules together in one module In one of my bags , When you want to transplant a function , Think about the acid .... Of course, if you have a unique taste , Then when I didn't say )

Ideal :

Idealized words , reference : Ideal .png; The project structure is clear , The vein is clear
According to the layering in the figure , Explain in detail :
Shell layer :app module
The internal code only writes app The skeleton frame , for instance , Yours app It's a structure like this :

There is N individual TAB, adopt Fragment To switch modules . This architecture is certainly not uncommon .
This is the time , Shell layer app module, Just write This one above UI Just the framework code of the architecture , As for how many modules , You need code to read the configuration for display . You asked me how to write this UI Frame ? There are a lot of online ,
If I can't find , Come to me github
The business layer
Our business module , The external interface may be a
Activity
* *(** for instance , Login module , Only one... Is provided
LoginActivity
, There is and only one window )
perhaps
It's a
Fragment
, As above, ( Typical app framework .png), If app Of UI The frame is switched
Fragment
If you change the business module .
use
business
** This directory , Include all business modules , Each module is independent
module
, In this way, business code isolation is realized , You can see all the business modules at a glance , As the saying goes , Be clear at a glance .
Functional component layer
Every business module , Inevitably, you need to use some utility classes , There are plenty of them
The third party SDK The second encapsulation of
, There are plenty of them
My own tool class ,
Or write it yourself
Custom control
, And it could be
All business modules need Auxiliary modules
, It's all here .
Routing framework layer
Design this floor , I want you to app In all of the Activity, Business module Fragment, And data interaction between modules , All by This layer is responsible for
gradle Unified profile
Some overall situations within the project gradle Variable , Put it here , The whole project works
module Compile settings
setting.gradle Configure the to compile module; You can also do more complex operations , such as , Write gradle Code to automatically generate some module, Avoid the trouble of artificial creation .
At the end
For programmers , A lot of technology learning is “ Defensive ” Of . in other words , We are learning for the future . The purpose of our learning new technology , Or to apply it in a new project , Or just for future interviews . But anyway , It must not “ To stop ”, It can't be abandoned .





The following content of the article will give the interview questions of Ali and meituan ( answer + analysis )、 Interview question bank 、Java Core knowledge points, etc
原网站版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207051914469816.html