Java and uml-2-Object-oriented

Source: Internet
Author: User



In the Internet era today, the advent of artificial intelligence and big data cloud computing, we can see that the computer world is increasingly approaching the human world.



from the programming language, it is also increasingly approaching human language, from the beginning of the machine language, to the later assembly language, to the high-level language and lower language demarcation C language, until now the object-oriented language.



machine language, as can be seen from the name, machine language is the computer can be directly recognized, we all know that the computer is binary, can only recognize 0 , 1 . Then the problem comes, using machine language program, that is not learning computer, but the electronic, therefore, machine language is really professional, perhaps only those technical big coffee can swim in the machine world, for us this kind of ordinary people, can only far view.



Thus, the production of assembly language, the use of the label to represent the order, will greatly simplify the learning difficulty, this time should be our computer professionals spring began to come.



      c language generation, has been basically close to human language, of course, is the language of Europe and the United States, and see this blog post you, basically nothing to do with, because see this blog is basically Chinese. But no matter China the United States, at least c language in understanding, are simply too much. However, this time because the hardware development is not rapid, so basically just write some small programs or write some algorithms, such as algorithms, this is obviously more close to the logical ability, therefore, c language is also more focused on the expression of logic, that is, we usually do things, the first step to do, what to do next .... This sequential logic is very much in line with human beings, but we can also see that this is basically one thing to describe the world, so c language is also called structured process of language, emphasizing the algorithm or software running process.



with the development of hardware, the advent of large programs, the current program can not be used only by the program to express, and the word system may be closer. At this time, the idea of object-oriented is coming out. The so-called objects we can understand everything we see, people, cats, dogs, desks, computers, cell phones and so on all. are objects, before the process flow, such as the math test, do the problem,C language will be the first step, the second step of the description of the steps to do, but object-oriented is the message flow + object. To a problem, people do the problem, finish the answer to you.



650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/8A/37/wKioL1grD43y8BnKAAANoflorWg399.png-wh_500x0-wm_3 -wmp_4-s_4116455151.png "title=" Class1.png "alt=" Wkiol1grd43y8bnkaaanoflorwg399.png-wh_50 "/>



And in this, people specifically how to do, do not emphasize, so from can see the topic, people, answers, these nouns. Each noun is the object, "give the topic to the person", "the person finishes gives the answer" this is the message flow, namely the input and the output.






Of course, object-oriented is not to say that there is no process of things, for example, the topic to people, how to achieve, or the need for programmers to follow the implementation of the process, but in the overall structure, we do not emphasize the process, but emphasize the cooperation between objects, from the part of the whole, the realization of the system.






The word "class" in object-oriented is common in our life, such as human beings, classification and so on. In object-oriented, the difference between class and object sometimes makes people confused. I'll show you the difference between a class and an object:






the difference between a class and an object is simple: The class is an abstract description, and the object is actually present. For example, human beings, is very abstract, can only describe what human beings have in common, such as, name, gender, age, address, but not specific, but specific to a person, such as Zhang San, male, Seven years old, Guangzhou, etc., before the common description of mankind is the class, Zhang San is an example of this class, which is the object. Here is an example: class to remember a word called: "Classification" is as follows:






mobile phones are classified as smartphones and non-smartphones, and smartphones have Samsung, Apple and. Non-smartphones have Oppo,nokia



Thus, it can be seen that their relationship is:



650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/8A/3B/wKiom1grD5yBemvCAAAxj3DtdXE582.png-wh_500x0-wm_3 -wmp_4-s_1687420851.png "title=" Class2.png "alt=" Wkiom1grd5ybemvcaaaxj3dtdxe582.png-wh_50 "/>


code example:/** * @author LeiGao24 * @data 2016.11.15 * Mobile--phone * Smartphone---zhineng * non-smartphone-Feizhineng */class Phone{}class zh Ineng extends Phone{}class Feizhineng extends phone{}//Specifies the entry for the program to run the main function, that is, where to start executing the program//Because Java is all object-oriented, This means that all the statements in Java must be in the class. So declare a class and put the main function in the class. Class Main{public static void Main (string[] args) {//Generate object Zhineng sanxing=new Zhineng (); Zhineng apple=new Zhineng (); Zhineng =new Zhineng (); Feizhineng oppo = new Feizhineng (); Feizhineng nokia = new Feizhineng ();}}


The above code can be a good description of the above-mentioned diagram.



Classes and objects should be understood from the above. So the question is, how do we usually describe an object?



Usually from two aspects, one is its property, and the other is its function.



For example, then the above example, phone properties: brand, size, phone function: Call, send SMS



650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/8A/3B/wKiom1grEnmgvFtvAAAUR-tGE2U157.png-wh_500x0-wm_3 -wmp_4-s_173348343.png "title=" Phone1.png "alt=" Wkiom1grenmgvftvaaaur-tge2u157.png-wh_50 "/>



As a result, we can extend the code as follows:





/*** @author  leigao24* @data  2016.11.15*   mobile phone--phone*   smartphone---zhineng*   Non-smart phones  -- feiZhiNeng*/class phone{String brand; String size;public void call () {System.out.println ("phone call  ...");} Public void mesaage () {System.out.println ("Phone message");}} class zhineng extends phone{//because the smartphone is a subclass of the phone, that is, the child,//So, the smartphone also contains the brand, size, call, texting//But, Phone calls and text messages each phone implementation of the way is different,//So, to call and send SMS two ways to re-write Public void call () {System.out.println ("Smart call ....") This phone brand is "+this.brand+", the size of this phone: "+this.size);} Public void mesaage () {System.out.println ("smart texting .... This phone brand is "+this.brand+", the size of this phone: "+this.size);}} Class feizhineng extends phone{public void call () {System.out.println ("non-intelligent call ....") This phone brand is "+this.brand+", the size of this phone: "+this.size);} Public void mesaage () {System.out.println ("non-intelligent texting ....") This phone brand is "+this.brand+", the size of this phone: "+this.size);}} Specifies the portal where the program runs the main function, that is, where to start executing the program//Because Java is all object-oriented, that is, all Java statementsMust be in the class. So declare a class and put the main function in the class. Class main{ public static void main (String[] args) {//Generate object zhineng sanxing= New zhineng (); sanxing.brand= "Samsung"; sanxing.size= "5 inch"; Sanxing.call (); Sanxing.mesaage (); zhineng apple= New zhineng (); apple.brand= "Apple"; apple.size= "4 inch"; Apple.call (); Apple.mesaage ();feizhineng oppo =  New feizhineng (); oppo.brand= "Oppo"; oppo.size= "2 inch"; Oppo.call (); Oppo.mesaage (); feizhineng nokia =  new feizhineng (); nokia.brand= "Nokia"; nokia.size= "3 inch"; Nokia.call (); Nokia.mesaage ();}}


Operation Result:



650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/8A/37/wKioL1grFwLxZdXpAABTkHuGPN4337.png-wh_500x0-wm_3 -wmp_4-s_3213066263.png "title=" Result1.png "alt=" Wkiol1grfwlxzdxpaabtkhugpn4337.png-wh_50 "/>



This article is from the "http://sunshine2624.blog.51cto.com/3959438/1873262" blog, please be sure to keep this source.



Java and uml-2-Object-oriented


Related Article

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.