Our test environment and has shown signs of OOP

Some students did not take into account the iPhone,Swift language learning but at least we will have OS X operating system,Our code shows will be completed in OS X,Using the CLI interface。So although it looks old and was,But believe me take the GUI make you worry a lot - because that is another matter。

So now,Let's say hello and OOP

We take a look,Developing with OOP in the end is what it looks like?

We are not taking into account the high level of development,Then we go to all the functions implemented in place of the output text,Merely to demonstrate the "development" process itself。

Boss appeared

"This time we do a cell phone!"

Ok,We have to develop a mobile phone:

You see,Our phone system has four methods can be used?

"Our second-generation products to be available on the Internet!"

Ok,We then developed a cell phone out:

"Our three generations of products have Wifi!"

Ok,After all, the boss who is giving you money,We go again, right:

"You can go home。”

Ok,More than three phone code no matter to whom will read worried - redundant portions too much - we have done so much wasted effort! No wonder the boss will quarrel and finally got the ax for the final salary。

This time the sky just listen to bang Duang,OOP drive to,Let's look at how to save the object-oriented field:

Abstract superclass

We say that three generations have turned off the phone calling and texting functions,Then we developed a class,They abstracts:

"You do that and then the eggs!" (Do not worry boss)

With this foundation,We subclasses from CellPhone,Each subclass has all the functions of the parent class,We just add extra features like:

Check it out? This will save a lot of duplication of development time!

"Do not get too excited,I would also like to develop a tablet! "

We all know that in fact is a large tablet phone,Then we only need to add tablet functions just fine on the phone,A change in hardware on ok ~

"I do not want a tablet instead of a phone's location,Their access to the Internet but can not make calls and send text messages! "

Ok,We calling and texting functions rewrite:

All right,Now the birth of the tablet。

"Humph,I want all of the devices can be turned on with the sound! "(This is a vindictive boss you ah ~ ~)

But no,Do not roll up your sleeves and go to war - reconstruction of the entire system is not necessary。

All right,We just changed the startup of the parent class,All subclasses will have this feature。

 

Summarize

Ok,Overall, our chestnuts are not very appropriate,But it does not prevent us to understand the connotation of OOP is not it? Through mechanisms such as inheritance and rewriting of OOP,We can very quickly build a superstructure based on previous base。But also specifies the type of,We can also easily modify the previous code without affecting the subsequent code。

In particular, it is time to develop in people,OOP is to save the life of the program ape,We can be more convenient to use someone else has developed written wheels (library),You may or may not continue to develop in a certain time。

 

but,What classes and objects in the end what is it? Inheritance exactly how to run it? We come to understand the next lesson。

Original article written by LogStudio:R0uter's Blog » Our test environment and has shown signs of OOP

Reproduced Please keep the source and description link:https://www.logcg.com/archives/1107.html

About the Author

R0uter

The non-declaration,I have written articles are original,Reproduced, please indicate the link on this page and my name。

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *