java-Horse Soldier Design Pattern Learning notes-bridging mode

Source: Internet
Author: User

I. Overview

1. Application of Bridge Mode: (1) two dimension extension (2) permutation combination

Second, the Code

1.gift.java

1  Public class Gift {23     protected Giftimpl Giftimpl; 4 }

2.giftimpl.java

1  Public class Giftimpl {23 }

3.warmgift.java

1  Public classWarmgiftextendsGift {2 3      PublicWarmgift (Giftimpl giftimpl) {4         //call the Giftimpl of the parent class5          This. Giftimpl =Giftimpl;6     }7 8 @Override9      PublicString toString () {Ten         return  This. GetClass (). GetName () + "-----" +Giftimpl.getclass (). GetName (); One     } A}

4.wildgift.java

1  Public classWildgiftextendsGift {2 3      PublicWildgift (Giftimpl giftimpl) {4         //call the Giftimpl of the parent class5          This. Giftimpl =Giftimpl;6     }7 8 @Override9      PublicString toString () {Ten         return  This. GetClass (). GetName () + "-----" +Giftimpl.getclass (). GetName (); One     } A}

5.flower.java

1  Public class Flower  extends  giftimpl {23 }

6.ring.java

1  Public class extends Giftimpl {23 }

7.mm.java

1  Public classMM {2     3     PrivateString name;4 5      PublicString GetName () {6         returnname;7     }8 9      Public voidsetName (String name) {Ten          This. Name =name; One     } A      -}

8.boy.java

1  Public classBoy {2 3     PrivateString name;4     5      Public voidpursue (mm mm) {6Gift Gift =NewWildgift (NewFlower ());7 give (gift, mm);8 System.out.println (gift);9     }Ten  One      Public voidGive (Gift Gift, mm mm) { A          -     } -}

9.test.java

1  Public class Test {23    @org. Junit.test4public     void Test () {5         New Boy (); 6         B.pursue (new  MM ()); 7     }89 }

Iii. Results of operation

java-Horse Soldier Design Pattern Learning notes-bridging mode

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.