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)