Big talk Design Pattern _ appearance Pattern

Source: Internet
Author: User

For example, you can purchase funds to indirectly buy stocks to earn income.

Package COM. WZS. design;/*** big talk design mode -- page105 appearance mode ** @ author administrator **/public class appearancemodel {public static void main (string [] ARGs) {fund = new fund (New stock1 (), new stock2 (), new stock3 (); fund. buyfund (); fund. sellfund () ;}}/** Fund */class fund {private stock1 stock1; private stock2 stock2; private stock3 stock3; Public Fund (stock1 stock1, stock2 stock2, stock3 stock3) {This. stock1 = stock1; this. stock2 = stock2; this. stock3 = stock3;} // purchase fund public void buyfund () {stock1.buy (); stock2.buy (); stock3.buy ();} // sell fund public void sellfund () {stock1.sell (); stock2.sell (); stock3.sell ();} public stock1 getstock1 () {return stock1;} public void setstock1 (stock1 stock1) {This. stock1 = stock1;} public stock2 getstock2 () {return stock2;} public void setstock2 (stock2 stock2) {This. stock2 = stock2;} public stock3 getstock3 () {return stock3;} public void setstock3 (stock3 stock3) {This. stock3 = stock3 ;}/ ** stock */abstract class stock {public abstract void round (); public abstract void buy ();} /** stock 1 */class stock1 extends stock {@ overridepublic void buy () {system. out. println ("stock 1 buy. ") ;}@ overridepublic void upload () {system. out. println ("stock 1 sold. ") ;}}/** stock 2 */class stock2 extends stock {@ overridepublic void buy () {system. out. println ("stock 2 buy. ") ;}@ overridepublic void upload () {system. out. println ("stock 2 sell. ") ;}}/** stock 3 */class stock3 extends stock {@ overridepublic void buy () {system. out. println ("stock 3 buy. ") ;}@ overridepublic void upload () {system. out. println ("stock 3 sell. ");}}

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.