Go to the object village of Java (2)

Source: Internet
Author: User

This time, we talk about the difference between object-oriented and process-oriented, and the advantages of object-oriented.

Listen to the voice of programmers writing programs with process-oriented thinking: What is the things this program have to do? What procedures do we need?

Aha, my idea as a qualified quasi-Java programmer is: what is the things in this program......who is thekey players?

From this, we can visualize the difference between object-oriented and process-oriented. When it comes to procedural writing, it is concerned with what sequence the program is doing, and object-oriented programs are concerned with what is in the program (the formal term is Class).

For example, the project manager will give you a need to write a graphic (triangle, positive direction, circle) to rotate the program that plays the music (mp3 format) simultaneously (which you often see in the player, when playing music, the singer's avatar is turning).

As a senior C-language player of the small-size classmate, a little thought to find the program's two important processes: graphics rotation, play music. So he program is:

Rotate (shapenum) {

Make the shape rotate 360º

}

PlaySound (shapenum) {

Use Shapenum to lookup which

AIF sound to play, and play it

}

I thought for a long time and found the class: graphics. haha

Continue to think in terms of object-oriented thinking, what are the attributes of this class? I didn't mention it in demand. What about the behavior of the class? There is the act of spinning, and putting music on. Well, after the analysis, write the program.

Class Cirlce {

Ratate () {

Code to ratate a circle

}

PlaySound () {

Code to ratate a circle

}

}

Class Square {

Ratate () {

Code to ratate a circle

}

PlaySound () {

Code to ratate a circle

}

Now the project manager says the demand has changed.

Object-oriented three major features: inheritance, polymorphism, so that the code reuse rate has increased older.

Object-oriented advantages are very, very much, they can go deep experience, programming learning in their own attempt is very important.

A small suggestion:

If you ' re stuck on a exercise, try talking about it out loud. Speaking (and hearing) activates a different part of your brain. Although it works best if you had another person to discuss it with, pets work too. that's how our dog learned polymorphism.

Go to the object village of Java (2)

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.