Stealth and ignorance

Source: Internet
Author: User
How can we protect ourselves?
In fact, the best way is to keep yourself mysterious, expose your information as little as possible, and make people ignorant.
Good software design pursues this realm.
Here the "Citizen" refers to "customer ". Expose as few APIs as possible and give the customer a "thin" interface so that the customer does not know how to perform the operation. This is beneficial to others.
I still use sortingAlgorithm. Our goal is to provide the Sorting Algorithm to users through a dynamic library.


A simple policy mode is used here. A user calls a function to sort a given linked list. He cares about speed rather than the sorting algorithm. The Code is as follows:
Csort *Psort = new cbubblesort;
Psort-> sort (plist );

So what should we provide to users?
A: Sort. Lib, sort. dll, sort. H, bubblesort. h
what information does the user know?
answer: we know that the sorting database currently provides a Bubble Sorting Algorithm. (Of course, You Need To bubblesort. h I have no choice but to name it out, but this is not what we advocate .)
What do users need?
answer: it is possible that the shell sorting algorithm performs better.
what are you going to do?
answer: reconsider the shell sorting algorithm.

 We cannot be held by users. We need to protect ourselves, so that the less users know, the better, and the more information they have. Now, how can we hide information?

 Method 1: factory Mode
What is a factory? To put it simply, a factory is the place where some products are produced. As for how to produce products, users do not care how the products are produced. It is said that many hotels are currently unhealthy, but the food delivered is still very good. The customers care about the food. As for the environment in which the food is burned, they will not know it all.
Here I encapsulate the creation process of sorting algorithms in a simple factory,UMLThe figure is as follows:


The Code is as follows:
Csort * psort = sortfactory ();
Psort-> sort (plist );
Now let's discuss the same issue again.

 
So what should we provide to users?
answer: sort. lib, sort. DLL, sort. h, sortfactory. h
what information does the user know?
answer: I don't know what sort algorithm to use.
What do users need?
answer: if the performance still goes off, the possibility of raising demand is reduced.
what are you going to do?
A: No requirement, just do your own thing.

 If I change the Sorting Algorithm, do you know? The answer is yes. I don't know. The user does not need to do anything, even the re-compilation is not required, because the interface function has not changed.

 Method 2: proxy Mode
Agents are no stranger to everyone. Simply put, they are organizations that spend money to ask people to work for you. For example, if a house intermediary wants to rent a house, the intermediary will handle it for you. The customer does not know how to handle it.
See how the proxy mode hides information:

the Code of a client call is as follows:
csort psort = csortproxy;
psort-> sort (plist );
try to ask the same question above, the answers are basically the same. If you want to replace the sorting algorithm, modify csortproxy sort function, it has no impact on the client.

What are the benefits?
I don't want to explain it in detail. The above discussion clearly shows the benefits. I will simply sum up the following:
1.Make yourself active.
2.Make people ignorant and block users' mouths. The less you know, the less you need.
3.Good scalability. As long as the interface remains unchanged, I want to change it.

Need your support
After all, personal knowledge is limited, and there may be better methods. If you think of a good method, please share it with me, I will joinArticle.

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.