Architecture is not built overnight. Hopefully, one day, we can find the sense of accomplishment in architecture from the code we write instead of just running away
Android Architecture Learning Path series
What is architecture
I also have a little understanding of architecture. After reading some articles related to architecture, I have gained my own understanding based on actual project experience.
What is architecture about? This point can be seen as the name implies, architecture = frame + structure, that is, a frame of the whole and the combination of components between the structure. Programmer, of course, may be different to the project architecture style and habits are different, but the underlying thought should be similar, such as we could hear the cocoon son of “separation of concerns”, “low coupling and high cohesion”, “extensible, reusable easy maintenance and so on,” after hearing these words, feel understood, and feel what also don’t understand, seems to have something, When you’re about to start coding, you’re probably thinking, “I’m running out of time, so I’ll just write it.”
Architecture is not far away from us, but is everywhere in our actual development. It is a very general concept, from framework selection, componentization, etc., down to business code, design patterns can be called part of architecture. For architecture learning, I think the first thing is to have a certain understanding of object-oriented (abstraction, inheritance, polymorphism, etc.) and design principles, and then combine some commonly used Android architectures such as MVVM, MVP, MVI and other ideas, the basic and theoretical understanding is clear, architecture in daily development, more thinking, more combination of theory and practice. It all adds up bit by bit.
Make fun
I think every programmer probably has one of these experiences (hyperbole) when writing code:
- Who wrote this tuo code, how to write ah, I need how to add code!
- (try to walk carefully in the shit mountain, and add new code) write good uncomfortable, shit more change more Chou…
- Well, let’s reconstruct it and end it all!
- One day of reconstruction: I said, how come there is a mine buried here? Let me arrange it. Wow, how there is strange logic here, I asked my former colleagues that it is the need of PM change; Well, whatever you like.
- Several days later -> Git Revert -> Work
- In the original shit mountain and then pull a tuo, OK, very stable, lift test.
New employees are always thinking about refactoring, while experienced old people have long known that if they can not move other people’s code, they will not move (DOge). Shit is mutual, you come and go to live forever. When it comes to writing code, it’s all about reciprocity
The reasons behind this are XX
The joke is not directed at any one person, but it is quite normal because technology is evolving and iterating, and businesses are enriching and refactoring, so at the time, the code seemed to be good, just because of the step by step development and some historical baggage (PM:??). Gradually, the original architecture may not be able to keep up with business requirements. After all, architecture is not immutable. Business is developing, technology is iterating, and entropy increases normally. At a certain point, assess costs and revenues and honestly restructure your needs.
Of course, although with the development of business, entropy is inevitable, but also pay attention to the quality of your code, after all, you should not be behind the colleagues who take over when secretly laughing at your shit too Chou, unless you really hold the idea of finishing this vote yo-yo (DOGE).
In short, the reasons can be divided into two kinds:
- Product development, technology update iteration
- Everyone’s coding habits may be different and varied
How to do
Learn Object orientation well
I’ve heard that even people who are Java veterans for many years may not pay much attention to object orientation in their development, and I often miss this point. Oh no, I’m not a Java veteran.
As for the difference between object oriented and process oriented, there are many introductions on the Internet, just copy a copy:
- Object orientation: Object orientation is a style that takes classes as the basic unit of code, accessed through objects, and owned
Encapsulation, inheritance, abstraction, polymorphism
Four features are the building blocks that make it smarter. - Process-oriented: analyze the steps needed to solve the problem, and then use functions to achieve these steps step by step, when using one by one can be called, more emphasis on the design of functions.
At the beginning of the requirements, don’t rush to write code, think about the nature of the requirements, use object-oriented thinking to abstract the process, not just a few classes.
For example, the background boot requirement at my old employer was like this: there may be one or more different boot options for different Android versions, and you need to try each version. The straightforward way to do this would be if else spark and lightning all the way through, but I thought this would be too difficult to maintain, so I abstracted each Starter into a Starter class:
abstract class Starter {
// Do the background boot thing
abstract fun handle(context: Context, intent: Intent)
// Whether it meets specific Android versions and business scenarios
abstract fun satisfy(a): Boolean
}
Copy the code
String together, then put these startup mode in a similar chain of responsibility design pattern to work, the specific code is not posted, interested can look at previous article: combat | Android background road to start practice Activity. Maybe now look at the code at that time, will feel a little immature, but the programmer is not always progress ~
Then is those commonly used object-oriented design patterns, the truth of these design patterns is very useful, there are six object-oriented design principles, these online should be a lot of articles will say, here is not redundant.
Design architecture
As mentioned earlier, with the development of technology and business, architecture has been iterated step by step. For example, in the beginning, the single architecture integrates user interface, business logic, and data management, and in the later stage, the architecture is divided according to business and technology, such as MVC, MVP, MVVM, MVI, as well as modularization and componentization. Service registration and discovery, the more complex Clean architecture, the Android Version of Redux architecture, and so on. Lots of them. Oh, good roll.
There are times when you wonder if so many new things are coming out of the box as a necessary iteration of the technology or as a result of OKR, KPIs being rolled out (DOGE). But what can I do? I still have to learn. These articles plan behind slowly arrange, give me early on when added the flag of two and a half years, refueling Android | 2021 year-end summary!
However, no matter how many architectures there are, they all serve the business. There is no perfect architecture, but the one that fits the current needs is the best.
Write in the last
When writing code, think twice and think about whether your code is where it should be and in the form it should be.
Architecture is not achieved overnight. I hope that one day, we can find the sense of accomplishment of architecture from the code we write, rather than the idea of running away after a few work. This series will be updated all the time to record the footprints of my learning on the road of architecture and remove the mysterious veil of architecture one by one.
If the content of the article is wrong, welcome to point out, common progress! If you think it is good, leave a thumbs-up before you go. Your three companies are my motivation to write!