"Big talk design mode" Ruby Code: Appearance mode

Source: Internet
Author: User

Demand:

Investors buy and sell stocks

Preliminary code:

#-*-encoding:utf-8-*-#stock 1classStock1defbuy puts'stock 1 Buy'EnddefSell puts'stock 1 Sell'EndEnd#Stock 2classStock2defbuy puts'stock 2 Buy'EnddefSell puts'Stock 2 Sell'EndEnd#Stock 3classStock3defbuy puts'stock 3 Buy'EnddefSell puts'Stock 3 Sell'EndEnd#National Debt 1classNationalDebt1defbuy puts'National debt 1 buy'EnddefSell puts'National Debt 1 sell'EndEnd#Real Estate 1classRealty1defbuy puts'Real Estate 1 Buy'EnddefSell puts'Real Estate 1 sell'endends1=stock1.news2=STOCK2.NEWS3=stock3.newn1=NATIONALDEBT1.NEWR1=Realty1.news1.buys2.buys3.buyn1.buyr1.buys1.sells2.sells3.selln1.sellr1.sell

Problem:

It can be found that users need to understand the stock, national debt, real estate situation, need to participate in the specific purchase and sale of these projects, coupling is very high.

Improved code

#-*-encoding:utf-8-*-#stock 1classStock1defbuy puts'stock 1 Buy'EnddefSell puts'stock 1 Sell'EndEnd#Stock 2classStock2defbuy puts'stock 2 Buy'EnddefSell puts'Stock 2 Sell'EndEnd#Stock 3classStock3defbuy puts'stock 3 Buy'EnddefSell puts'Stock 3 Sell'EndEnd#National Debt 1classNationalDebt1defbuy puts'National debt 1 buy'EnddefSell puts'National Debt 1 sell'EndEnd#Real Estate 1classRealty1defbuy puts'Real Estate 1 Buy'EnddefSell puts'Real Estate 1 sell'EndEnd#Fund CategoryclassFund attr_accessor s1, S2, S3, N1, R1defInitialize S1=stock1.new S2=stock2.new S3=stock3.new N1=nationaldebt1.new R1=Realty1.new Enddefbuy s1.buy s2.buy s3.buy n1.buy r1.buy Enddefsell S1.sell S2.sell s3.sell N1.sell R1.sell endendf1=Fund.newf1.buyf1.sell

Benefits: Users do not need to know a variety of stocks, just buy a sell fund.

Appearance mode:

Provides a consistent interface for a set of interfaces in a subsystem that defines a high-level interface that makes this subsystem easier to use.

"Big talk design mode" Ruby Code: Appearance mode

Related Article

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.