[Original · tutorial · serialization] "Android's big talk Design Model"-Chapter 8 of the structural model of the design model: appearance model MM is also infatuated with stock trading?

Source: Internet
Author: User
<Big talk design model> description and copyright notice of this tutorial

Guoshi studio is a technical team dedicated to enterprise-level application development on the Android platform. It is committed to the best Android Application in China.ProgramDevelopment institutions provide the best Android enterprise application development training services.

Official contact information for Enterprise Training and Development Cooperation:

Tel: 18610086859

Email: hiheartfirst@gmail.com

QQ: 1740415547

Guoshi studio is better for you!

L this document references and uses free images and content on the Internet, and is released in a free and open manner, hoping to contribute to the mobile Internet and the smart phone age! This document can be reproduced at will, but cannot be used for profit.

L if you have any questions or suggestions about this document, go to the official blog

Http://www.cnblogs.com/guoshiandroid/ (with the following contact information), we will carefully refer to your suggestions and modify this document as needed to benefit more developers!

L The latest and complete content of "big talk design mode" will be regularly updated on the official blog of guoshi studio. Please visit the blog of guoshi studio.

Http://www.cnblogs.com/guoshiandroid/get more updates.

Appearance ModeMmAlso infatuated with stock trading? 

Appearance ModeUse Cases: 

I chatted with MM on QQ. MM said that her cousin earned a lot of money in stock trading. She always heard from her cousin about futures, stocks, government bonds, and other technical terms, it is said that there is still a magical fund. You only need to hand over the funds to relevant institutions, and these institutions can help you directly make money, you don't have to worry about the specific process! MM asked Gg in QQ what it meant. When mm described the information in QQ, GG looked at the information and checked the relevant explanations of these terms online, so I directly copied it to QQ and sent it as follows:

Fund: you have spent money to hire someone to help you stock up. If you lose money, you are charged for the service fee and fund custody fee.

Futures: It means spending money on things that you cannot get the actual goods. You can buy short sales and pay a deposit to enlarge the transaction, and increase the risk and income.

Stock: You are the shareholder of a company. If you feel that the stock has risen, you can sell it at any time. The only thing you know is lost.

National debt: the country asks you to borrow money and then gives you interest, but it must be credited to you after the specified deadline expires.

Appearance mode explanation: 

The appearance pattern is a commonly used software design pattern, which belongs to the structure pattern. It provides a unified high-level interface for a group with similar functions, such as class libraries and subsystems. This high-level interface is displayed to the user on a simple and consistent interface, making it easier to use subsystems and groups.

Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.

Appearance ModeUMLFigure: 

The builder mode involves the following roles:

Facade role: defines a simple calling interface for the caller.

Client (clients) Role: calls an internal group that provides a function through the facade interface to read and write data resources of each interface of the subsystem.

Group (packages) Role: function provider. A group (module or subsystem) that provides functions ).

The UML diagram of the appearance mode is as follows:

A more specific UML diagram is shown below:

In-depth analysis of appearance Modes:

In a real application system, a sub-system may consist of many classes. The sub-system client needs to interact with some classes in the sub-system for their needs. Direct interaction between the client and subsystem classes will result in high coupling between client objects and subsystems. Any modification similar to the class interface in the subsystem will affect all customer classes dependent on it. Facade Pattern provides a higher level and simpler interface for the subsystem, thus reducing the complexity and dependency of the subsystem. This makes subsystems easier to use and manage.

Appearance is a class that provides simple interfaces for subsystems and clients. When the correct application looks, the customer no longer interacts directly with the class in the subsystem, but with the appearance. The appearance is responsible for Class Interaction with the subsystem. In fact, the appearance is the interface between the subsystem and the customer, so that the appearance mode reduces the coupling between the subsystem and the customer. In this way, the client can remain unchanged when the subsystem changes.

Although the client uses a simple interface provided by the appearance, when necessary, the client can directly access the low-level interface in the subsystem as it does not exist. In this case, the dependency/coupling between them is the same as that of the original one.

Analysis andCodeImplementation:

In the above application scenarios, futures, stocks, and government bonds belong to different single investment types, and funds can combine these types, that is, the Fund is equivalent to the appearance of futures, stocks, and government bonds. The public only needs to use the fund interface for financial investment.

The UML Model diagram is as follows:

 

Create a stock class:

PackageCom. diermeng. designpattern. facade. impl;

/*

* Stock class

*/

Public ClassStock {

/*

* Purchasing stocks

*/

Public VoidBuy (){

System.Out. Println ("Purchasing stocks ");

}

}

 

Establish national debt:

PackageCom. diermeng. designpattern. facade. impl;

/*

* National Debt

*/

Public ClassNationaldebt {

/*

* Purchase of government bonds

*/

Public VoidBuy (){

System.Out. Println ("purchasing government bonds ");

}

}

Create a category:

PackageCom. diermeng. designpattern. facade. impl;

/*

* Category class

*/

Public ClassFutures {

 

Public VoidBuy (){

System.Out. Println ("purchasing futures ");

}

}

 

Fund Establishment:

PackageCom. diermeng. designpattern. facade. impl;

 

 

/*

* Fund type

*/

Public ClassFund {

// Declare the stock

PrivateStock stock;

// Declare national debt

PrivateNationaldebt guozai;

// Declare futures

PrivateFutures;

 

// Constructor instantiate declared Variables

PublicFund (){

This. Guozai =NewNationaldebt ();

This. Stock =NewStock ();

This. Futures =NewFutures ();

}

 

// A fund type

Public VoidFunda (){

This. Guozai. Buy ();

This. Futures. Buy ();

}

// B fund types

Public VoidFundb (){

This. Guozai. Buy ();

This. Stock. Buy ();

}

// C fund types

Public VoidFundc (){

This. Futures. Buy ();

This. Stock. Buy ();

}

 

// D BASE gold type

Public VoidFundd (){

This. Guozai. Buy ();

This. Stock. Buy ();

This. Futures. Buy ();

}

}

Finally, we create a test client:

PackageCom. diermeng. designpattern. facade. client;

 

ImportCom. diermeng. designpattern. facade. impl. Fund;

 

/*

* Test the client

*/

Public ClassFacadetest {

Public Static VoidMain (string [] ARGs ){

// Fund creation

Fund jijin =NewFund ();

 

// Call the corresponding method

System.Out. Println ("***************************");

Jijin. Funda ();

System.Out. Println ("***************************");

Jijin. Fundb ();

System.Out. Println ("***************************");

Jijin. fundc ();

System.Out. Println ("***************************");

Jijin. fundd ();

System.Out. Println ("***************************");

}

}

The output result is as follows:

***************************

Purchase government bonds

Purchase futures

***************************

Purchase government bonds

Purchase stock

***************************

Purchase futures

Purchase stock

***************************

Purchase government bonds

Purchase stock

Purchase futures

***************************

 

Advantages and disadvantages of appearance mode:

Advantages:

By providing a unified external interface, the appearance mode can avoid direct connections between external systems and subsystems, thus reducing the degree of dependency between systems. On the other hand, how external systems want to directly interact with subsystems can also bypass the appearance mode, which makes the external systems very flexible to use subsystems.

Disadvantages:

The appearance mode is limited to the interfaces provided by external systems. From this perspective, it limits the flexibility of external systems for subsystem calls.

Overview of the appearance mode:

Generally, the appearance mode is used in the following scenarios:

1. Provide a simple interface for a complex subsystem. Subsystems tend to become more and more complex due to continuous evolution. Using the appearance mode can keep external systems simple in calling subsystems, however, users who need to call details can directly call the subsystem in the appearance mode.

Second, the appearance mode can be introduced to separate a sub-system from its clients and other subsystems, which improves the independence and portability of the sub-system.

Third: when building a hierarchical structure, you can use the appearance mode to define the interface for external interaction at each layer. At this time, the layer and layer only need to communicate through the appearance, so as to simplify the dependency between the layer and the layer.

The appearance mode is a widely used mode. For example, the well-known MVC mode uses the appearance mode. In MVC Architecture, each layer does not need to know details of other layers, but can be called through interfaces between layers. This greatly facilitates development.

Tip:

Generally, the appearance mode provides convenient and consistent external interfaces for subsystems when multiple subsystems exist in a complex system. However, this does not prevent direct interaction between external systems and subsystems, because the external system can directly interact with the subsystem through the appearance.

For stocks, futures, and funds, funds are equivalent to their appearance. In addition, they can combine multiple different appearances to attract investors.

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.