<Big talk design model> description and copyright notice of this tutorial
L this document references and uses free images and content on the Internet, and is released in a free and open manner, hoping to contribute to the mobile Internet and the smart phone age! This document can be reproduced at will, but cannot be used for profit.
L if you have any questions or suggestions about this document, go to the official blog
Http://www.cnblogs.com/guoshiandroid/ (with the following contact information), we will carefully refer to your suggestions and modify this document as needed to benefit more developers!
L The latest and complete content of "big talk design mode" will be regularly updated on the official blog of guoshi studio. Please visit the blog of guoshi studio.
Http://www.cnblogs.com/guoshiandroid/get more updates.
Guoshi studio is a technical team dedicated to enterprise-level application development on the Android platform. It is committed to the best Android Application in China.ProgramDevelopment institutions provide the best Android enterprise application development training services.
Official contact information for Enterprise Training and Development Cooperation:
Tel: 18610086859
Email: hiheartfirst@gmail.com
QQ: 1740415547
QQ: 148325348
Guoshi studio is better for you!
View other parts:Overall description and Chapter index of this tutorial
PDF download link
Interface Programming-Why? Direct education
Use Cases:
"There will be a meeting here in sixteen years; couples will never lose their trust in each other." Yang ran to the cliff with grief and grief. He saw the words of the little girl who had stayed on the stone wall, that is, the words of surprise and sorrow: "16 years! Why wait until 16 years ?!".
However, the letter has been made, and the infatuated Yang Guo can only wait for sixteen years.
After leaving the cliff, Yang started his hard-waiting and thinking, while practicing his passion, of course, at the beginning
You cannot forget to eat the healing herbs. Later, Yang once met the Millennium artifact and the artifact, and then began to cultivate the martial arts that are dedicated for defeat. There is nothing to do, and it is also a great pleasure to practice the sword with enthusiasm. "Lovesickness is useless, but it is nothing more. If there is a certain period of time, what will be the same as suffering? Where is the dark ?!", This was the first time the ghost was born. Hour
It's almost over 16 years. At this time, Yang Guo's power has become a success. Imagine that the 16-year period is approaching. In my heart, I can't help but feel deeply and excited! After worshipping and defeating his old man's family, Yang Guo and Shen Diao began to go to that 16-year-old appointment together. All beings are excited and excited.
Yang, who once again went out of the Jianghu region, punished and defended against evil and helped the weak. Soon, he was named a "God-carved man ". In my heart, I imagined a smile from the young girl in the past. I imagined how she spent the past 16 years and gave birth to a stronger feeling of Acacia and meeting each other.
The day is coming!
On the side of the cliff, the beauty of the trail has not been found yet, and the sky is full, jumping down the cliff...
Fortunately, there was an abyss under the cliff. Yang Guo was not dead. After Yang was awakened by the water to the shore, he saw many little bees. At a glance, he recognized the little dragon girl's bees, is mofeier nearby? Finally, under the water of Shen tan, Yang found his love for sixteen years. In the past, the little dragon girl learned that she had no medicine to save and jumped out of the cliff. During the 16-year period, she was just trying to prevent Yang from being easy. But after the cliff, the little dragon girl did not die. Then, in the bottom of the valley, she slowly recovered. A lover is a perfect person.
Definition:
An interface is a set of methods and features. An interface only has features of a method and has no implementation of a method. Therefore
These methods can be implemented by different classes in different places, and these implementations can have different behaviors (functions ).
An interface is an abstraction of abstraction.
Interfaces are standards and commitments.
For interface programming, do not express the dependency reversal principle for specific programming.
Interface Programming is also called interface-oriented programming. For interface programming, you must first design a series of interfaces to separate the Design and Implementation. You only need to reference the interface when using it, due to the decoupling of various parts of the system. As shown in:
Story analysis:
A wonderful example of Interface Programming is that we will meet again here in sixteen years. In addition, a "contract" was added at the end. The implication is that we have promised to meet again here for sixteen years. We both need to follow this agreement. According to the story above, after the little dragon girl and Yang developed an interface, they jumped down the cliff, regardless of their experience, because at this time, she no longer needs to worry about how to meet her on the river after sixteen years. She only needs to meet her here after sixteen years. That is to say, she is targeting and using both interfaces. How can she implement Yang, at this time, she is suffering from a serious illness and cannot take care of it. After Yang had read this agreement, he had to do it despite being helpless. The specific implementation is as follows: Go back to eat troughs to adjust yourself, and then use the artifact as a companion to practice martial arts, know that it has become a powerful and powerful thing, and then do chivalrous things on the rivers and lakes, then, according to the letter and sixteen years later
To the side of the cliff, and the little dragon girl slowly raised at the bottom of the valley, 16 years later, the body has been recovering, and more charming. When Yang did not see the little dragon girl, he jumped along the cliff and followed the standard of "what is the love of the world.
To sum up, the little dragon girl and Yang decided on the interface, and then they worked independently on the interface and finally met each other.
Interface-oriented programming will improve the maintainability, scalability and reusability of programs in the future. If you use another one directly in a class, the two classes will be closely linked together, and it will be difficult to make changes in the future. For interface programming, when the business changes, we only need to use a new class to implement the interface, and the client can still use the interface to reference the new class, it also guarantees the immutability of the client. In this way, the client and the implementation end do not affect each other and maintain their respective independence. Just like Xiao longfemale and Yang Guo, after setting up the constraints for sixteen years, they don't have to worry about how to proceed to this Agreement. They just need to follow the agreement to do things. Independent of each other. As shown in:
JavaCodeImplementation:
Create a new "contract" interface, which must be implemented by Yang Guo and Xiaolong. The Code is as follows:
PackageCom. diermeng. designpattern. Dating; /* * Agreed interfaces set by Yang Guo and Xiao Long female */ Public InterfaceDating { /* * Agreed Interfaces */ Public VoidDating (); } |
Then, the implementation classes of Yang Guo and Xiaolong female are created to implement the above interfaces respectively. The Code is as follows:
PackageCom. diermeng. designpattern. Dating. impl; ImportCom. diermeng. designpattern. Dating. Dating; /* * Yang Guo's interface implementation */ Public ClassYangguoImplementsDating { /* * Name */ String name; /* * Default empty Constructor */ PublicYangguo (){} /* * Constructor for passing in the name parameter */ PublicYangguo (string name ){ This. Name = Name; } PublicString getname (){ ReturnName; } Public VoidSetname (string name ){ This. Name = Name; } /* * (Non-javadoc) * @ See COM. diermeng. Dating. Inter. Dating # dating () * Yang Guo's implementation of the Convention */ Public VoidDating (){ If(This. Getname ()! =Null){ System.Out. Println (This. Getname () + ":" + "The meeting will be held again after 16 years. Couples should never lose trust in each other "); } Else{ System.Out. Println ("The meeting will be held again in 16 years; do not lose trust in couples "); } } } |
PackageCom. diermeng. designpattern. Dating. impl; ImportCom. diermeng. designpattern. Dating. Dating; /* * Implementation of interfaces */ Public ClassXiaolongnvImplementsDating { /* * Name */ String name; /* * Default empty Constructor */ PublicXiaolongnv (){} /* * Constructor for passing in the name parameter */ PublicXiaolongnv (string name ){ This. Name = Name; } PublicString getname (){ ReturnName; } Public VoidSetname (string name ){ This. Name = Name; } /* * (Non-javadoc) * @ See COM. diermeng. Dating. Inter. Dating # dating () * Implementation of conventions */ Public VoidDating (){ If(This. Getname ()! =Null){ System.Out. Println (This. Getname () + ":" + "The meeting will be held again after 16 years. Couples should never lose trust in each other "); } Else{ System.Out. Println ("The meeting will be held again in 16 years; do not lose trust in couples "); } } } |
Create a test class with the following code:
PackageCom. diermeng. designpattern. Dating. client; ImportCom. diermeng. designpattern. Dating. Dating; ImportCom. diermeng. designpattern. Dating. impl. xiaolongnv; ImportCom. diermeng. designpattern. Dating. impl. yangguo; /* * Clients that have been tested by Yang Guo and Xiaolong female */ Public ClassDatingtest { Public Static VoidMain (string [] ARGs) { // Instantiate instances separately Dating yangguo =NewYangguo ("fun "); Dating xiaolongnv =NewXiaolongnv ("long er "); // Call the respective methods Yangguo. Dating (); Xiaolongnv. Dating (); } } |
The program running result is as follows:
After: The meeting will be held again 16 years later. The couple will never lose promises. Long Er: The meeting will be held again in 16 years. The husband and wife will never lose promises. |
Existing applications:
Java is the language for face-to-face object programming, and one of the core aspects of object-oriented programming is to program the interface, not implement programming, and Mark interface Java in Java API. io. serializable and Java. RMI. remote is what we often encounter. The following uses Java. io. serializable is used as an example to describe,Source codeAs follows:
Package java. IO; Public interface serializable {} |
Shows the UML diagram:
Of course, interface programming is everywhere in the use of the J2EE framework. For example, in www.babasport.com, almost every part of the interface is programmed. The impressive thing is that Baba Sports Network encapsulates crud and other basic operations on the database into a unified interface, this makes code compilation and database operations very convenient. Of course, Java 5's wildcard technology is also used here. Interested readers can learn the source code of Baba Sports Network.
Tip:
A commitment is a debt owed. Therefore, do not make commitments easily.
Yang Guo and Xiaolong made sixteen years of effort to make a commitment.
In software design and coding, if an interface is established, a commitment is made to the customer, which has almost no chance of change. The longer it takes, the longer it takes, this is because the use of your interface by others has been spread all over the world. Of course, the premise is that your excuses are outstanding so that you can gain trust and consumption by many people.
Don't say it easily: "I love you", because this is a promise of life.
Note: This document references and uses free and open images and content on the Internet and is released in a free and open manner, hoping to contribute to the mobile Internet and the smart phone age! This document can be reproduced at will, but cannot be used for profit.