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