Big talk Design Pattern _ decoration pattern

Source: Internet
Author: User

To see pretty girls, I don't know what to wear, so I will start to match them one by one. experiment with the best effect...

Package COM. WZS. design;/*** big talk design mode -- page53 decoration mode ** @ author administrator **/public class decorativepattern {public static void main (string [] ARGs) {person XC = new person ("coriander"); system. out. println ("first dress up:"); wearsneakers pqx = new wearsneakers (); // broken sneakers bigtrouser KK = new bigtrouser (); // pants tshirts dtx = new tshirts (); // large T-shirt pqx. decorate (XC); KK. decorate (pqx); dtx. decorate (kk); dtx. show (); system. out. PR Intln ("\ n type 2:"); wearleathershoes PX = new wearleathershoes (); // shoes wearsuit xz = new wearsuit (); // suit weartie LD = new weartie (); // tie PX. decorate (XC); lD. decorate (PX); xz. decorate (LD); xz. show () ;}/ ** person */class person {private string name; Public Person () {}public person (string name) {This. name = Name;} public void show () {system. out. print (name + "dress up. ") ;}}/** apparel */class finery extends person {priv Ate person;/** dress up */Public void decorate (person) {This. Person = person;} @ overridepublic void show () {If (null! = Person) {person. show () ;}}/ ** large T-shirt */class tshirts extends finery {@ overridepublic void show () {system. out. print ("big t-shirt"); super. show () ;}/ ** pants */class bigtrouser extends finery {@ overridepublic void show () {system. out. print ("Pants"); super. show () ;}/ ** broken sneakers */class wearsneakers extends finery {@ overridepublic void show () {system. out. print ("Broken sneakers"); super. show () ;}/ ** suit */class wearsuit extends finery {@ overridepublic void show () {system. out. print ("Suit"); super. show () ;}/ ** tie */class weartie extends finery {@ overridepublic void show () {system. out. print ("Tie"); super. show () ;}/ ** shoes */class wearleathershoes extends finery {@ overridepublic void show () {system. out. print ("Shoes"); super. show ();}}

Output result:

 
The first type of dress: Big T-shirt, slashes, sneakers, and pickles. The second type is the suit, tie, and shoes.

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.