A simple way to learn Object-Oriented Programming

Source: Internet
Author: User

 

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.