One, two, three
Let's repeat the principles:
Minimum Information Principle: Method interfaces should only transmit the most necessary business information.
There are two layers:
1. Do not expose technical information
2. Business Information cannot be duplicated
Business Information Analysis
Do not worry about technical issues. Think about the data required to do this?
1. What is the original value (used for display)
2. Which values are possible)
3. What operations should I perform after a value is clicked (this is the core business)
4. What to do after return (refresh)
Where are some other problems?
5. Where can I refresh the returned value? The caller asked us to arrange the display (for example, a div). Refresh is to refresh the position we display.
6. What if nothing is returned? Look at it.
The final method interface is designed as follows:
public static MvcHtmlString AjaxValue(int id, string value, string[] values, string urlFormat, string ajaxOnSuccess = null)
How can I add more IDs? Because we need to display many such ajaxalue, which can be distinguished by ID.
What is urlformat? It is used to define the format of the generated Ajax link. Please refer to the following call (slightly problematic ):
@SFCUI.AjaxValue(story.ID, effortValue.ToString(), Effort.EffortPlannedValues, "/SFC/Efforts/AjaxSetEffortPlanned?itemID=" + story.ID + "&value={0}", ajaxOnSuccess: "refreshLeftPad");
The order of these parameters is described as follows: story. ID to modify the current value of effrotvalue ,... possible effortplannedvalues value ,".... "The selected value will be placed in the href format {0} of ajaxlink in the future. ajaxonsuccess is the correct function to be returned.
Analysis of Interface Design Principles
In theory, placing this sentence in any cshtml requires all the business information, and the rest is a technical problem. In this method, we can solve the problem and leave it alone, this is called"Do not expose technical informationSub-principle.
How can we say "Some Problems exist? Because story. ID appears twice here, the first is an integer parameter passed in, the second is used to generate the urlformat passed in, the second redundant, should be changed:
@SFCUI.AjaxValue(story.ID, effortValue.ToString(), Effort.EffortPlannedValues, "/SFC/Efforts/AjaxSetEffortPlanned?itemID={0}&value={1}", ajaxOnSuccess: "refreshLeftPad");
In this way, ID and value are placed in 0, and ajaxlink can be combined.
Now, it is not enough to delete any letter or punctuation. This is called"Business information cannot be duplicatedSub-principle.
After understanding this principle, you can confirm the interface parameters (I like to call it "appearance") in the first time, and then start writing.
Of course, sometimes the most concise interface cannot be written for the first time, so you can try to "Bulk" first, whether it is a function or a bunch of Divs, first write it out and then finish writing it, and then encapsulate it into the simplest form.
In the next article, we will outline the implementation in ajaxlink.