Recently, new employee training was required. The organizer asked me to do an object-oriented training. To be honest, I have worked on this training for several years and found it difficult to do it.
First, you are facing new people. There is not much experience yet. It is often illusory to talk about ideas.
Second, this idea is abstract, and it is even more difficult for everyone to gain something in the training.
However, the requirement is the command! I still have to think about how to clarify this issue.
Today, when I checked the code of a new employee, I found that he wrote a class called TCompare, and I asked what it was, he told me that it is used for comparing folders and files. So I think it is necessary to say a few words.
That's what I told him,
First, if you compare folders, is it better to change the TComare class to TFolderCompare? Otherwise, it is difficult for others to see the responsibilities of your class from the name. On the contrary, it will confuse readers. In turn, you, as the author, do not express your design intent.
2. If you compare folders, Will files be compared? (He said yes) Should there be a TFileCompare class?
Third, if you have two classes and abstract the interfaces, then there will be another TCompare class.
The above is a bit cool, but I think I have grasped the key point and summarized it as follows:
First, Object-Oriented Programming starts with naming! Class responsibilities are very important!
2. Perform at least the next layer of Object-Oriented Analysis on the tasks assigned to you.
3. After the business is clearly analyzed, the object is abstracted.
The second one is particularly important, for example:
Let you write the function of comparing folders. Instead of writing a folder comparison class, you have to look at another layer, such as file comparison? Comparison of text files and binary files?
In other words, if you want to write a car type, you should not write only one TCar, but at least analyze the power system, steering system, and linkage system. If you only write one TCar, it is called object-based programming. If you have analyzed the next layer, it is object-oriented programming.
I think I should have caught it. This is a simple way to learn object-oriented ideas, that is, the next layer of analysis!
Object-oriented thinking is a complex design concept. It is not difficult to find a path. It is really difficult to find a simple path. I hope I can gain a glimpse of it.