Tutorials to .com

Tutorials to .com » Software » Game-developer » The heroes from Warcraft to devise a mechanism to pry into the idea of object-oriented

The heroes from Warcraft to devise a mechanism to pry into the idea of object-oriented

Print View , by: iSee ,Total views: 9 ,Word Count: 1337 ,Date: Wed, 10 Jun 2009 Time: 12:36 PM

Mad cow shed tears in 2002 from thesummer and it has the right balanceonly. Are you also a fan of Warcraft you? On the other hand, however, can not afford to lose the play-chi, I do not know you played these games, it is not and I am thinking more like something else, such as software design idea of what and so on. Oh, Imetamorphosis

Make a good back (cough twice intentionally) ! Understand object-oriented, the key is the three basic concepts: package, inheritance and polymorphism. I explain, respectively, in accordance with the order.

Packaging, what is it? Very simple, in a time when you write code, you must have a variable declaration Private experience for you? You do not want the outside world to the pollution it - this is the package. In a category, it's internal variables (you can directly attribute them that is) is hidden by default in the outside world. If you want to control a class, then please tell him what you want it to do it - As for how it works, the rights you do not understand.

Whir, youwhen those heroic attributes, such as the value of life, magic value, the value of such aggressive, in fact, is packaged into each type of hero's. Why we can read these attributes do? That is because these classes to read the attributes of our interface. For example, you want to read or set on the value the lives of women priests, you are experienced in knowing the following steps. On your first daughter of the priest said: "Priestess of months, I'd like to see the vitality of your values, can?" She said: "Well, I always have and I value the current vitality of the state published in the I bar, go see your own. As for how I put my release from these values, you have no right to know. "and then was carried away and push for too much of you, I would like the status bar from directly modify the value of her life. She will be very annoyed and said: "But I do not provide such a service! You have to let me drink water wells on do it!" Oh ~ ~ ~ drinking water wells in the moon another and life is linked to the hook value of approach you, you can modify through the vitality of the value of the interface. This interface has played a bound user's end, to avoid the data is illegal pollution, to achieve the original intention of the package.

Read attributes as the above method is also called "read-only approach" has the same "write-only approach" kind of the same token, I do not bother to repeat the arguments. Need to say is that not all have internal attributes of the interface leading to the outside world. Keep in mind that type of design is always in its user so that it looks more simple, so if a particular category in which the authors believe that there is no need for a data member by using the categories of people perceived the existence of it, then If that day he did not drink too much wine, he would not provide any data on the corresponding interface. In this way, this property has been completely up package.

Of course no one will stop you put the statement into a variable Public, but no one can recommend that you do so, so this statement before you are convinced that this is necessary. You can Imagine if the woman on priests to control the value of her life made public the right to complete, then the fairness of the game to speak of what it?

"Oh ... ... the total section" Are you open latrine Dayton "category is all about you! To hide its data, and through its open approach to the achievement of its users and the types of interaction. Warcraft hero in so many each family of four, plus six neutral hero, the hero is the 22 Class 22 Ha! "Then I will be feeling your head and said:" Yes, you can really think of. Hmmm, there are four types of magic, life has value, the value of magic, the biggest offensive force,value, defense force, etc. then 22 heroes, we can write slowly, no problem ... ... "

Then you suddenly forced open my hand: "Wait a minute! 22 categories since there are so many common attributes and methods, you do not try to directly writean abstract category of a hero then?" I said thought you mad, because this is the first origin of the introduction of inheritance. Warcraft is not only a hero in the case, you look thin, and machine live in a world also filled with such examples. If you do not use them to inherit the derivative relationship, and the impulse to each category are designed as a separate category, then you will have to repeat the number of lines of code to write? So I want to seem a little frightening, right? Therefore, we have to inherit such a mechanism because a large extent, improved the efficiency of our software.

Let us again turn back to our heroes of the above-mentioned categories of the abstract. I guess you do not dare to imagine that such a category has been created as examples of what is it? Well, anyway, I dare not imagine. Because I tried to do this, I always come to mind one of the fertilized eggs of invertebrates, soft red, ghosts know that it will maturewhat kind, likes and dislikes of the way anyway.

Please pause here a little to think about it ... ... 12 seconds ... ...

If you are smart, you will ask me: "Well, since do not want to be a realization of the abstract base class, then this type of approach which should be how to write? For example UseUltimateSkill ... ..." ah, good question! Since we do not want to be the creation of abstract class as an example, it is very simple, we do not have bothered to write code, but our methods in this class to sign a unilateral agreement before - which may be referred to as "MustInherit" right agreement. Agreement is so written in the body: "I you want to inherit is not it? No problem! However, you have to fill you on my way to the realization of this. Otherwise, you will inherit, I do not count on it!"

So every hero would rush their magical powers of the significant. Demon Hunter said: "I most want to bullying, let me come to a good rogue Station!" Great Master strange to sing in the side of the bang: "You take, since II untouchables.instantaneous transferit. "Death Knight is also not to be outdone:" I am the best, I have to let other people to achieve back to life! "This could be bad music chiefs How Stella:" It's not as early as the first high fashion, and let me look at my own ability to rejuvenate , it also fully automated! "... ... was a hero on the way 22 has its own magic - a method name is a mix Zhenzhen ah!

Sluggish when you erase the mouth of saliva and asked: "Oh, brother shed tears, this polymorphism is not it?"

Ha ha I said boy nonsense.


Game Developer Tutorial Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.