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/1873665" blog, please be sure to keep this source.



Java and uml-2-object-oriented


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.